Bug 114534 - Feature request: extend VLA support in C++
Summary: Feature request: extend VLA support in C++
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 14.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: C++VLA
  Show dependency treegraph
 
Reported: 2024-03-30 18:45 UTC by nightstrike
Modified: 2024-03-30 21:21 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description nightstrike 2024-03-30 18:45:34 UTC
See https://gcc.gnu.org/pipermail/gcc-help/2024-March/143369.html for reference.

The documentation at https://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html states that VLAs are supported in C++ as an extension.

Compiling the following:

void f(int a, int b[a]);
void f() {
  int c[2];
  f(2, c);
}

with g++ -std=gnu++20 results in the error: "use of parameter outside function body before ']' token".  The docs say nothing about partial support of VLA, just that they can be used.

Where this is useful as an extension is in the somewhat reasonable case of including a C header in a C++ program.  If that C header declares a function using a C99 VLA, it would be awesome if g++ were to accept it in -std=gnu++ mode (and it would be fine if it were rejected in -std=c++ mode).  Consider a situation where you cannot modify the header, and so have to use it as-is.

For comparison, clang added support for this feature in version 12.  It would be advantageous to have feature parity given that it started as a GNU extension.  Moreover, better interoperability with C is useful in its own right.
Comment 1 Drea Pinski 2024-03-30 19:15:42 UTC
I think this is a dup of bug 51352 really.
Comment 2 Drea Pinski 2024-03-30 19:18:15 UTC
(In reply to Andrew Pinski from comment #1)
> I think this is a dup of bug 51352 really.

And/or PR 97820 too.