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 c++/79476] New: C++ frontend ignores diagnostic pragma in macro


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

            Bug ID: 79476
           Summary: C++ frontend ignores diagnostic pragma in macro
           Product: gcc
           Version: 6.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jak@jak-linux.org
  Target Milestone: ---

Created attachment 40721
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40721&action=edit
Reproducer

We define three macros in APT:

        #define APT_IGNORE_DEPRECATED_PUSH \
                _Pragma("GCC diagnostic push") \
                _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
        #define APT_IGNORE_DEPRECATED_POP \
                _Pragma("GCC diagnostic pop")
        #define APT_IGNORE_DEPRECATED(XXX) \
                APT_IGNORE_DEPRECATED_PUSH \
                XXX \
                APT_IGNORE_DEPRECATED_POP

So you can do stuff like APT_IGNORE_DEPRECATED(f();). This does not work
correctly however. Compiling the attached file with the C compiler results in
no warnings, with the C++ compiler a warning is emitted for
APT_IGNORE_DEPRECATED(f();) but not for using push/pop macros explicitly around
the f(); in the other functions:

$ gcc -c -Wdeprecated-declarations a.c
$ g++ -c -Wdeprecated-declarations a.c
a.c: In function ‘int a()’:
a.c:15:27: warning: ‘int f()’ is deprecated [-Wdeprecated-declarations]
     APT_IGNORE_DEPRECATED(f();)
                           ^
a.c:8:3: note: in definition of macro ‘APT_IGNORE_DEPRECATED’
   XXX \
   ^~~
a.c:11:5: note: declared here
 int f() __attribute__((deprecated));
     ^
a.c:15:29: warning: ‘int f()’ is deprecated [-Wdeprecated-declarations]
     APT_IGNORE_DEPRECATED(f();)
                             ^
a.c:8:3: note: in definition of macro ‘APT_IGNORE_DEPRECATED’
   XXX \
   ^~~
a.c:11:5: note: declared here
 int f() __attribute__((deprecated));
     ^

According to cpp, all functions expand to the same code.

This used to work at some point a long time ago, but I can't remember when.

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