On Mon, 2 Oct 2023, Sandra Loosemore wrote:

> Going beyond that, though, I think we should also document that the standard
> syntax is now the preferred way to do it, and change the examples (except for
> the parts documenting the old syntax) to use the new standard syntax.  It's
> been accepted by the default -std= setting for both C and C++ since GCC 10,
> and my understanding is that C2x will be official by the time GCC 14 is
> released (so supporting the new syntax won't be just another GNU extension any
> more). Does this sound OK to everybody?

If you're documenting attributes in the [[]] form, you need to be a lot 
more careful to distinguish between an attribute on a declaration and one 
on the type of that declaration, for example, because those need to go in 
different places in the standard syntax (the laxity applied with 
__attribute__ that tries to guess what was meant and e.g. move an 
attribute from a declaration to its type doesn't apply with the standard 
syntax, which has precise rules in the standard for what entity an 
attribute in a given syntactic position appertains to).  In some cases 
this means that the [[]] attribute needs to go in a different position 
from __attribute__ in examples - in

int f (void) __attribute__ ((foo));

the GNU attribute in that position is considered a declaration attribute 
(but a function type attribute applied to a declaration will automatically 
be applied to the type instead) whereas

int f (void) [[gnu::foo]];

is only a function type attribute, not a declaration attribute [*], and

[[gnu::foo]] int f (void);

is only a declaration attribute, not a function type attribute.  (The 
version

int [[gnu::foo]] f (void);

applies the attribute to the int return type, which probably isn't what 
you want - unless you're e.g. using [[gnu::vector_size (16)]] to declare 
that the function returns a vector.)

To complicate things further, some attributes that are implemented as 
declaration attributes maybe logically should be type attributes but 
support for them on types hasn't been implemented - and if making such a 
GNU attribute into a type attribute in future, we might then need to 
consider appropriate compatibility for allowing it in both places even 
with the standard syntax.


[*] In the GNU syntax an attribute in this position is parsed as an 
attribute following a full declarator and any subsequent asm giving an 
external linkage name for the declaration.  In the standard syntax, an 
attribute in this position is part of a declarator immediately following a 
function declarator (and so could appear on nested function declarators, 
for example).  So while it looks superficially like "the same" position 
for the attributes, it's not at all the same syntactically.

-- 
Joseph S. Myers
jos...@codesourcery.com

Reply via email to