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

            Bug ID: 125908
           Summary: -Wpedantic subwarning -Wvla leaks out of push/pop
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: diagnostics
          Assignee: dmalcolm at redhat dot com
          Reporter: aaron.puchert at sap dot com
  Target Milestone: ---

Compile the following code:

void before(int n) {
    int vla[n];
}

#pragma GCC diagnostic push
#pragma GCC diagnostic error "-Wpedantic"
#pragma GCC diagnostic pop

void after(int n) {
    int vla[n];
}

Versions up to 12 emit:

<source>: In function 'void after(int)':
<source>:10:9: warning: ISO C++ forbids variable length array 'vla' [-Wvla]
   10 |     int vla[n];
      |         ^~~

Starting with version 13:

<source>: In function 'void before(int)':
<source>:2:9: warning: ISO C++ forbids variable length array 'vla' [-Wvla]
    2 |     int vla[n];
      |         ^~~
<source>: In function 'void after(int)':
<source>:10:9: warning: ISO C++ forbids variable length array 'vla' [-Wvla]
   10 |     int vla[n];
      |         ^~~

With #pragma GCC diagnostic error "-Wvla", the first warning disappears.

I think none of the warnings should be emitted, since they all happen outside
of the push/pop. Removing that makes them disappear for all versions that I've
tried.

Reply via email to