public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: NightStrike <nightstrike@gmail.com>
To: gcc-help <gcc-help@gcc.gnu.org>
Subject: g++ with VLA
Date: Sat, 30 Mar 2024 02:10:41 -0400	[thread overview]
Message-ID: <CAF1jjLspQ39Xu0tpKsFkxyFvgv72aqeUjZ8gVh5WBNaAPVnORw@mail.gmail.com> (raw)

https://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html

That doc 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.

Is there perhaps another option to achieve the intended behavior?

If it's not possible, can this be added?

If the consensus is that it shouldn't be added, could the docs at
least clarify what is supported and what is not in C++?

             reply	other threads:[~2024-03-30  6:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-30  6:10 NightStrike [this message]
2024-03-30  9:05 ` Jonathan Wakely
2024-03-30 18:39   ` NightStrike
2024-03-30 18:46     ` NightStrike

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAF1jjLspQ39Xu0tpKsFkxyFvgv72aqeUjZ8gVh5WBNaAPVnORw@mail.gmail.com \
    --to=nightstrike@gmail.com \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).