https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128412

            Bug ID: 128412
           Summary: [C23] Attribute specified on the declarator wrongly
                    applies to type and then wrongly reject (ignore
                    warning)
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
                CC: jakub at gcc dot gnu.org, jsm28 at gcc dot gnu.org
  Target Milestone: ---

This is a fallout of the OpenMP examples discussion
(internal examples issue #629) which has the following:

 int a[100] [[ omp::decl(declare_target) ]],
     b[100] [[ omp::decl(declare_target, link) ]];


A similar code without OpenMP is:

 int a[100] [[deprecated]], b[100] [[deprecated]];

which GCC rejects with

  warning: ‘deprecated’ attribute ignored

(And g++ rejects with:
  warning: ‘deprecated’ on a type other than class or enumeration definition
and clang/clang++ rejects with
  error: 'deprecated' attribute cannot be applied to types )

* * *

Side remark: All three compilers accept it when writing it as
'attribute-specifier-sequence declaration-specifiers init-declarator-list':
  [[deprecated]] int a[100], b[100];
and print the proper warning when used.

* * *

Back to the original example:

 int a[100] [[deprecated]], b[100] [[deprecated]];

this seems to fall into:

  declaration-specifiers init-declarator-list(opt) ;

for init-declarator == declarator and then

  direct-declarator:
     identifier attribute-specifier-sequence(opt)

which is ISO/IEC 9899:2023 [here: N3096] under "6.7 Declarations" (page 96)
and then "6.7.6 Declarators" (page 124) – which then continues on page 125 with
the following in paragraph 5:

"If, in the declaration "T D1", D1 has the form
    identifier attribute-specifier-sequenceopt
  then the type specified for ident is T and the optional attribute specifier
  sequence appertains to the entity that is declared."

Which seems to make this case valid.  [Likewise for C++, but I still need to
dig the standard; Tom S. believes it works likewise in that case.]

Reply via email to