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

            Bug ID: 69507
           Summary: bogus warning: ISO C does not allow ‘__alignof__
                    (expression)’
           Product: gcc
           Version: 6.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: ---

The __alignof__  operator is a GCC extension to the C language whose documented
purpose is

  "to inquire about how an object is aligned, or the minimum alignment usually
required by a type."

While C11 provides the similar alignof operator that can be applied to types
(but not objects), prior versions of the C standard have no such feature.

Thus, the __alignof__  operator provides useful functionality not available in
any version of C.  Yet, when it's used with an object as an operand, GCC issues
the following warning in pedantic mode.  Not only is the warning unhelpful
(there is no other available feature that could be used instead), it's also
incorrect (ISO C says nothing about __alignof__).

As a data point, none of the three GCC-compatible compilers I've tested issues
a warning for this construct even in the strictest mode.

$ cat t.c && /home/msebor/build/gcc-trunk-git/gcc/xgcc
-B/home/msebor/build/gcc-trunk-git/gcc -S -Wall -Wextra -Wpedantic t.c
int a;
int i = __alignof__ (a);
t.c:2:9: warning: ISO C does not allow ‘__alignof__ (expression)’ [-Wpedantic]
 int i = __alignof__ (a);
         ^~~~~~~~~~~

Reply via email to