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

--- Comment #7 from Lewis Hyatt <lhyatt at gcc dot gnu.org> ---
The testcases mentioned so far in this PR (the original report, and the
reduction in Comment 5) started failing in r13-1544, because that revision
added #pragma GCC diagnostic to the set of pragmas that are registered in
preprocess-only mode, including in -fdirectives-only. But the same issue has
existed always it seems for other pragmas similarly registered; for instance
this testcase fails since gcc 9 and before:

=====
$ cat t2.cpp
#pragma message "hello"
#ifdef t
#endif

$ gcc-9 -E -fdirectives-only t2.cpp > /dev/null
t2.cpp:1:9: warning: extra tokens at end of #ifdef directive
    1 | #pragma message "hello"
      |         ^
=====

I think with -fdirectives-only, #pragma is not meant to be registered or
processed.

The below patch fixes all testcases mentioned so far:

=======
diff --git a/gcc/c-family/c-pragma.cc b/gcc/c-family/c-pragma.cc
index 142a46441ac..e9bcd1869d0 100644
--- a/gcc/c-family/c-pragma.cc
+++ b/gcc/c-family/c-pragma.cc
@@ -1647,7 +1647,8 @@ c_register_pragma_1 (const char *space, const char *name,

   if (flag_preprocess_only)
     {
-      if (!(allow_expansion || ihandler.early_handler.handler_1arg))
+      if (cpp_get_options (parse_in)->directives_only
+         || !(allow_expansion || ihandler.early_handler.handler_1arg))
        return;

       pragma_pp_data pp_data;
========

However it doesn't fix an analogous one using "#pragma omp" even though it
suppresses the registration of the pragma there too. I will track that down and
follow up with a complete patch.

Reply via email to