C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Mark std::assume_aligned as noexcept

From: Tymi <tymi.cpp_at_[hidden]>
Date: Sun, 29 Jun 2025 13:49:41 +0200
It sure has preconditions, but so does start_lifetime_as,
start_lifetime_as_array, to_pointer etc etc, and they ARE specified as
noexcept

Can't verify it because every single implementation marks it as noexcept
anyway.

Tymi.

On Sun, 29 Jun 2025, 13:47 Jonathan Wakely, <cxx_at_[hidden]> wrote:

>
>
> On Sun, 29 Jun 2025, 11:06 Tymi via Std-Proposals, <
> std-proposals_at_[hidden]> wrote:
>
>> [ptr.align] specifies that `std::assume_aligned` throws *nothing*, so why
>> isn't it already marked as `noexcept`?
>>
>
> Because it has a precondition.
>
> Current signature:
>> `template [[nodiscard]] constexpr T* assume_aligned(T* ptr);`
>> Proposed signature:
>> `template [[nodiscard]] constexpr T* assume_aligned(T* ptr) noexcept;`
>>
>> Impact on the standard: none
>> Implementation: add noexcept specifier
>>
>> Reason: Better codegen on some compilers with exceptions (because of
>> noexcept),
>>
>
> Have you verified this?
>
>
> after all this function is meant to be an optimisation point. Another
>> smaller reason to use this function is noexcept functions, because some
>> static analysers are not happy with using not noexcept functions in
>> noexcept context...
>>
>>
>>

Received on 2025-06-29 11:49:55