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

Alejandro Colomar <foss+...@alejandro-colomar.es> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |foss+gcc@alejandro-colomar.
                   |                            |es

--- Comment #7 from Alejandro Colomar <foss+...@alejandro-colomar.es> ---
I think this is a bug in GCC.

The standard says that the entire _Pragma() is removed in translation phase 4. 
That makes the rest of the expression be valid by the time it reaches phase 7,
and thus syntactically it is correct.

Here I have a reproducer that is causing me pain:

alx@debian:~/tmp$ cat pragma.c | nl -ba
     1  int
     2  f(int n, int a[n])
     3  {
     4          return ({
     5                  _Pragma("FOO diagnostic push");
     6                  _Pragma("FOO diagnostic ignored
\"-Wsizeof-array-argument\"");
     7                  sizeof(a);
     8                  _Pragma("FOO diagnostic push");
     9          });
    10  }
    11  
    12  int
    13  g(int n, int a[n])
    14  {
    15          return (
    16                  _Pragma("FOO diagnostic push")
    17                  _Pragma("FOO diagnostic ignored
\"-Wsizeof-array-argument\"")
    18                  sizeof(a)
    19                  _Pragma("FOO diagnostic push")
    20          );
    21  }
alx@debian:~/tmp$ gcc -Wall -Wextra -Wno-unknown-pragmas
-Wno-sizeof-array-argument -S pragma.c
alx@debian:~/tmp$ sed -i s/FOO/GCC/ pragma.c 
alx@debian:~/tmp$ gcc -Wall -Wextra -S pragma.c
pragma.c: In function ‘g’:
pragma.c:16:17: error: expected expression before ‘#pragma’
   16 |                 _Pragma("GCC diagnostic push")
      |                 ^~~~~~~
pragma.c:13:14: warning: unused parameter ‘a’ [-Wunused-parameter]
   13 | g(int n, int a[n])
      |          ~~~~^~~~
pragma.c:21:1: warning: control reaches end of non-void function
[-Wreturn-type]
   21 | }
      | ^


I want to avoid using the ({}), so I'd like to be able to write g().

And the ironic thing is that it works if the pragma is not understood (FOO), as
GCC probably removed it as required by the standard.  But it seems that when
the _Pragma is understood, something remains (probably to be able to suppress
the diagnostics in phase 7.

Reply via email to