[Bug preprocessor/97498] New: #pragma GCC diagnostic ignored "-Wunused-function" inconsistent

matthewp515 at gmail dot com gcc-bugzilla@gcc.gnu.org
Mon Oct 19 23:49:57 GMT 2020


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

            Bug ID: 97498
           Summary: #pragma GCC diagnostic ignored "-Wunused-function"
                    inconsistent
           Product: gcc
           Version: 9.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: preprocessor
          Assignee: unassigned at gcc dot gnu.org
          Reporter: matthewp515 at gmail dot com
  Target Milestone: ---

Ubuntu Linux 20.04


#define STR(x) #x
#define WIGNORE(x, instrs) \
        _Pragma("GCC diagnostic push") \
        _Pragma(STR(GCC diagnostic ignored #x)) \
        instrs \
        _Pragma("GCC diagnostic pop")

// REPLACE

int main(void) {return 1;}


When REPLACE is replaced with:

WIGNORE(-Wunused-function,
static int f(int a) {return a + 1;}
)

The command:

gcc main.c -Wall -Werror -Wextra

fails (-Werror=unused-function). However, breaking up the command into separate
preprocessing and compilation stages:

gcc -E main.c -Wall -Werror -Wextra | gcc -x c -

passes.

When the macro is unwound by REPLACE being replaced with:

_Pragma("GCC diagnostic push");
_Pragma("GCC diagnostic ignored \"-Wunused-function\"");
static int f(int p) {return p + 1;}
_Pragma("GCC diagnostic pop");

The first command then passes. By adding a single backslash (\) right after the
implementation of f, as is required to keep the WIGNORE macro all as one, the
command fails. But how else can the macro be constructed?


More information about the Gcc-bugs mailing list