This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug preprocessor/70811] New: error on #pragma GCC diagnostic in an enum


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

            Bug ID: 70811
           Summary: error on #pragma GCC diagnostic in an enum
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: preprocessor
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

GCC gives a syntax error when #pragma GCC diagnostic appears in the
enumeraror-list of a definition of an enumerator (for example, when attempting
to suppress a warning about the constant-expression used to assign to one of
the enumerators, as in the example below).  GCC does not give an error when
#pragma push_macro is used in the same place.

I couldn't find anything about this limitation in the manual.  If it is a known
limitation or one that cannot be fixed the manual should be updated to mention
it.  AFAICS, the C standard allows implementations to fail to translate
programs with implementation-defined pragmas but it does require them to
document this (implementation-defined) behavior.

$ cat -n v.c && /home/msebor/build/gcc-trunk-git/gcc/xgcc
-B/home/msebor/build/gcc-trunk-git/gcc -S -Wall -Wextra -Wpedantic -xc v.c
     1  enum E
     2  {
     3      e = "a" - "a"
     4  };
     5  
     6  enum F
     7  {
     8  #pragma GCC diagnostic ignored "-Waddress"
     9      f = "b" - "b"
    10  };
    11  
v.c:3:9: warning: enumerator value for âeâ is not an integer constant
expression [-Wpedantic]
     e = "a" - "a"
         ^~~
v.c:8:9: error: expected identifier before â#pragmaâ
 #pragma GCC diagnostic ignored "-Waddress"
         ^~~

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]