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

            Bug ID: 119180
           Summary: GCC Accepts Non-Standard Variable-Length Arrays (VLAs)
                    in C++ Without Warnings
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: qurong at ios dot ac.cn
  Target Milestone: ---

GCC compiles code containing variable-length arrays (VLAs) and lambda captures
of VLAs without diagnostics, while Clang/MSVC correctly reject it. This
violates C++ standard rules (C++11 §8.3.4) and may mislead developers into
writing non-portable code.  

**Steps to Reproduce**:  
1. Save the following code as `test.cpp`:  
   ```cpp  
   template <typename T>  
   struct Container {  
       void f(int i) {  
           int ar[i];                 // Non-standard VLA  
           [&ar] { (void)ar; }();     // Lambda capture of VLA  
       }  
   };  

   int main() {  
       Container<int> obj;  
       obj.f(5);  
       return 0;  
   }  

2. Compile with GCC:

g++ -std=c++11 test.cpp  

Expected Result:
Compilation fails with errors about VLAs being forbidden in ISO C++, or at
least issues a warning when extensions are enabled.

Actual Result:
GCC compiles the code silently (or with -pedantic warns but still succeeds).

Environment:

Compiler: GCC 13.2.0

Flags: -std=c++11

Proposal:

Enhance Warnings:

Emit a warning by default for VLAs in C++ mode (similar to -Wvla in C).

Reject lambda captures of VLAs explicitly.

Documentation Update:

Clarify VLA support as a GNU extension in C++ mode.

Additional Notes:

Standard References:

C++11 §8.3.4: Array dimensions must be constant expressions.

C++11 §5.1.2: Lambda captures require complete types.

Impact: Non-portable code may fail on other compilers.

Compiler Explorer link: https://godbolt.org/z/YdEn56Gq1

Reply via email to