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

            Bug ID: 97820
           Summary: VLAs in function declarations fail to compile
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: josephcsible at gmail dot com
  Target Milestone: ---

Consider these 4 attempts at declaring a function:

void f1(int rows, int cols, int arr[rows][cols]);
void f2(int rows, int cols, int (*arr)[cols]);
void f3(int, int, int [*][*]);
void f4(int, int, int (*)[*]);

When I compile them with g++, they all have errors:

<source>:1:41: error: use of parameter outside function body before ']' token
    1 | void f1(int rows, int cols, int arr[rows][cols]);
      |                                         ^
<source>:1:47: error: use of parameter outside function body before ']' token
    1 | void f1(int rows, int cols, int arr[rows][cols]);
      |                                               ^
<source>:2:44: error: use of parameter outside function body before ']' token
    2 | void f2(int rows, int cols, int (*arr)[cols]);
      |                                            ^
<source>:3:25: error: expected primary-expression before ']' token
    3 | void f3(int, int, int [*][*]);
      |                         ^
<source>:3:28: error: expected primary-expression before ']' token
    3 | void f3(int, int, int [*][*]);
      |                            ^
<source>:4:28: error: expected primary-expression before ']' token
    4 | void f4(int, int, int (*)[*]);
      |                            ^

Since we support VLAs in C++ as an extension, I expected that all of these
would work.

https://godbolt.org/z/Wca9ra
  • [Bug c++/97820] New: VLAs in fu... josephcsible at gmail dot com via Gcc-bugs

Reply via email to