C++ Logo

liaison

Advanced search

Re: [wg14/wg21 liaison] [+externe Mail+] Re: [isocpp-core] Ignorability of attributes: draft wording, and concern about __has_c_attribute

From: Uecker, Martin <Martin.Uecker_at_[hidden]>
Date: Wed, 8 Feb 2023 20:42:19 +0000
Am Mittwoch, dem 08.02.2023 um 22:18 +0200 schrieb Ville Voutilainen:
> On Wed, 8 Feb 2023 at 21:57, Uecker, Martin via Liaison
> <liaison_at_[hidden]> wrote:
>
> > But testing for an attribute where then only syntax
> > is checked by the compiler seems completely useless
> > to me. I was asking for an example where this make
> > sense, because I could not come up with one.
> >
> > So is there one?
>
> Yes. Gasper Azman (pardon the lack of proper accentuations on s and z)
> explained it:
>
> You have 11 compilers, and one of them will just never report "I do
> useful things as a response to your attribute."
> You don't care, the 10 compilers cover your needs, and the 1 remaining
> one will be an oddball. Once you are confident
> that the 10 compilers do the useful thing and are not going to remove
> that functionality, and the oddball accepts
> your code, you remove the macrodetection of the attribute. (*)
>
> (*) Consider [[assume]]. The 10 compilers report whether they do
> optimizations based on assumption attributes,
> and the one doesn't matter because it's targeting an emulator where
> you don't run all that fast anyway. Once the
> 10 customer-hardware-targeting compilers say "I optimize based on
> assumptions", and the oddball says "I parse
> assumption attributes", you no longer need to feature-detect the attribute.

Thanks, but I am still missing something.

If the 11 compilers accept that attribute without warning,
I could unconditionally use the attribute without
feature-detect. So yes, a compiler supporting the
attribute by not emitting a warning, but not
implementing its semantics, can sometimes be
useful.

But this does not depend on what we require from
__has_c_attribute, because this is not even used.

I am looking for a scenario where a user wants
to get '1' from has_c_attribute even though the
attribute does nothing useful.

The best I could come up with is somebody using
two compilers: One which does not recognize the
attribute and emits a warning and one which
does syntax checking but nothing else. The
programmer wants to use the attribute because
he hopes it will be useful in the future. Having
it guarded by has_c_attribute would then give
syntax checking on the one compiler which does
this while avoiding a warning on the other.

But this scenario seems really far fetched.
When developing, one would at least have some
way of testing that it works as intended and
causes no harm.

A counter example would be maybe_unused. You
might want to feature-detect it to avoid a
warning for an unknown attribute. If a compiler
then says it supports it but then emits
an "unused" warning for a variable because
actually does not, then this would be annoying.

Martin












Received on 2023-02-08 20:42:24