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

            Bug ID: 90511
           Summary: bogus attributes silently accepted before struct or
                    union
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

When the attribute keyword is just before struct and union the GCC front-end
silently accepts any attribute, valid or not:

$ cat x.c && gcc -O2 -S -Wall -Wextra -Wpedantic x.c
__attribute__ ((bogus)) struct A { int i; };
__attribute__ ((totally, bogus (with, "arguments"))) union U { int i; };

The C++ front-end issues warnings:

x.c:1:32: warning: attribute ignored in declaration of ‘struct A’
[-Wattributes]
    1 | __attribute__ ((bogus)) struct A { int i; };
      |                                ^
x.c:1:32: note: attribute for ‘struct A’ must follow the ‘struct’ keyword
x.c:2:60: warning: attribute ignored in declaration of ‘union U’ [-Wattributes]
    2 | __attribute__ ((totally, bogus (with, "arguments"))) union U { int i;
};
      |                                                            ^
x.c:2:60: note: attribute for ‘union U’ must follow the ‘union’ keyword


Clang does as well:

x.c:1:17: warning: attribute 'bogus' is ignored, place it after "struct" to
      apply attribute to type declaration [-Wignored-attributes]
__attribute__ ((bogus)) struct A { int i; };
                ^
x.c:2:26: warning: attribute 'bogus' is ignored, place it after "union" to
apply
      attribute to type declaration [-Wignored-attributes]
__attribute__ ((totally, bogus (with, "arguments"))) union U { int i; };
                         ^
x.c:2:17: warning: attribute 'totally' is ignored, place it after "union" to
      apply attribute to type declaration [-Wignored-attributes]
__attribute__ ((totally, bogus (with, "arguments"))) union U { int i; };
                ^
3 warnings generated.

Reply via email to