Date: Wed, 20 May 2026 08:53:56 +0200
On 5/20/26 08:46, David Brown via Std-Proposals wrote:
>
> On 20/05/2026 01:16, Thiago Macieira via Std-Proposals wrote:
>> On Tuesday, 19 May 2026 12:58:24 Pacific Daylight Time Ville Voutilainen via
>> Std-Proposals wrote:
>>> In case this idea had actual convincing motivation, there's no reason
>>> *whatsoever* to do it with an attribute.
>>
>> Actually, an attribute might be appropriate here and simply let the compiler
>> warn if the function is actually called in code, instead of making it a hard
>> error. It would not be the end of the world if helper functions that are
>> usually used to compute a type more easily than a sequence of
>> std::conditional_t got actually called.
>>
>> Most of the time, such functions are private in some form or another, so only
>> the author of the code in question is even going to call them. The author can
>> already do a static_assert on a type-dependent false like std::declval does,
>> but will they bother to write that code?
>>
>>
>
> gcc has attributes [[gnu::error("This function must not be called")]]
> and [[gnu::warning("Calling this gives a warning")]]. The warning or
> error messages are not emitted if the call is eliminated (via dead-code
> elimination, only using it in unevaluated contexts, etc.).
>
> These should be reasonable candidates for standardisation?
>
> Then the OP can have:
>
> #define unevaluated error("Unevaluated contexts only")
>
> or whatever suits his preferences.
I'm not fond of standardizing any rules for dead code elimination.
That feels very much QoI, or a lot of work for little gain.
Jens
>
> On 20/05/2026 01:16, Thiago Macieira via Std-Proposals wrote:
>> On Tuesday, 19 May 2026 12:58:24 Pacific Daylight Time Ville Voutilainen via
>> Std-Proposals wrote:
>>> In case this idea had actual convincing motivation, there's no reason
>>> *whatsoever* to do it with an attribute.
>>
>> Actually, an attribute might be appropriate here and simply let the compiler
>> warn if the function is actually called in code, instead of making it a hard
>> error. It would not be the end of the world if helper functions that are
>> usually used to compute a type more easily than a sequence of
>> std::conditional_t got actually called.
>>
>> Most of the time, such functions are private in some form or another, so only
>> the author of the code in question is even going to call them. The author can
>> already do a static_assert on a type-dependent false like std::declval does,
>> but will they bother to write that code?
>>
>>
>
> gcc has attributes [[gnu::error("This function must not be called")]]
> and [[gnu::warning("Calling this gives a warning")]]. The warning or
> error messages are not emitted if the call is eliminated (via dead-code
> elimination, only using it in unevaluated contexts, etc.).
>
> These should be reasonable candidates for standardisation?
>
> Then the OP can have:
>
> #define unevaluated error("Unevaluated contexts only")
>
> or whatever suits his preferences.
I'm not fond of standardizing any rules for dead code elimination.
That feels very much QoI, or a lot of work for little gain.
Jens
Received on 2026-05-20 06:54:41
