From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by sourceware.org (Postfix) with ESMTPS id 6FF233858D1E for ; Sat, 30 Mar 2024 18:39:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6FF233858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6FF233858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::52b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711823967; cv=none; b=DPhJDd7Bcb9lHrdb36jnpK9vPCTR+DvfF3NtHMH0vww+oYq8f5QLqNqR6h5RahzDMPpOMW9tJG9WeeX0I7Wad8And7l+Y3PKRNZgs+uQM7ttbh3wNufgb2Bt03edJM8rUu8pvlmz8v9uML2/wFTc6IPLyLNjdY8hLp1SmlIHNIw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711823967; c=relaxed/simple; bh=SDC0KL9Wr+Mn6pfUODqg+ZTP4WIJgWldyAffCvVlDjo=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=oqb744NERdwgZWDuoF9D+sP9LlCbjmUXoX2VsvLwOvafkB6sSmD1pSxjqIAuE+j+zvk9+2yj2L4a1qr/i1z44frFZUIgj5IOEHvRe09oncaCh4ms2F1/R1ybWzW/dirJcjtEcnptJWbDPrlqTTL1bAvarH9lVw49FifX4DouaUs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-55a179f5fa1so3418175a12.0 for ; Sat, 30 Mar 2024 11:39:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711823963; x=1712428763; darn=gcc.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=tE/WTdJT+ijEpH8K7Cvt+6k3z26Pdn8Zip4hjOXEy/Y=; b=HAcv3ZVNrqvTAJGtyv7VAer8E4ynMnmd6LDjCktScXlMf6ftai4I7KvS/HMWXuK2Js GF9FGpR8226UA/9o5CiU3DHWe6jsYyhnyZq1E2OjXNGIrvmmvrbp4GvOoMaNMGpBvVbs oeQAgm3l0v7zx8Pi22Se8IIyKvV4wZ3+zdMolXvupVMXe8nDPjU8Flx+McLMcmo4n3/u H0dhdkZnMn0VJ/qJnDxCJbaMMgPbMW/FRx4TSRouPtGwDGqDULyY4B2qDQ208o2s1dzx 6ZeySN+VhKPtYMJqXIYWm4kHzd1KKlOX/RKV0/XMMTudeLUZyGI4GmKu5MeLK/AFx7+C aF/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711823963; x=1712428763; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tE/WTdJT+ijEpH8K7Cvt+6k3z26Pdn8Zip4hjOXEy/Y=; b=EKi0C2F18sslt3kruVPZNncuujlnUkDE33wPYSVj7Zb1Gw0cqwNX18h0YqrofhVW4v sS93HnJ6p4rbUp+jwrljUZgLGaa0wQo6nfjcENAnkGe9pr1WVPiHRrzv/ZSTKJC2/wW0 YIZZD93LODSIFnQWIorTGhzhcWz6iD5ot+XcOENPuDrq00tnYpGwvDQIMLLB/5lmaGLR Pkm46mK85ZyImA0H47xn2G+Jb/Uo76v9mmzmLu8qPGkyDiU1kRl4N06kGIR4TJi7yRB9 /MwSRcQGqfejgJ0Hp+PV7dCDOxHjpuZvrYpOxStaor4UnplnGCI9GLWfVXz5ELvK+uz1 GMEw== X-Gm-Message-State: AOJu0YwFwtz5OfIMDAWOZ4WioQdmHs4TiND5a1mKSdtI4uv+28tqbt3C Y4YYlp5WW8dmiFI7aFuhYrM+3OFSXeyO+WfDJyDDDB2ZiKVrpy/2SaTljBSLb6ye3zpJrNuJosZ CR91QA7djneFVF+txDf96jfCuMXY= X-Google-Smtp-Source: AGHT+IE5K9wPwaajC4oH/+mmc3KztXE+RD69Y54VXQDBAr6me8eVcO7JsKls7sMAVZVgqHSWcWdVbyQALNjhLYTwRxw= X-Received: by 2002:a17:907:a4c5:b0:a4e:37ac:79c8 with SMTP id vq5-20020a170907a4c500b00a4e37ac79c8mr3673314ejc.5.1711823962415; Sat, 30 Mar 2024 11:39:22 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: NightStrike Date: Sat, 30 Mar 2024 14:39:09 -0400 Message-ID: Subject: Re: g++ with VLA To: Jonathan Wakely Cc: gcc-help Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Sat, Mar 30, 2024 at 5:05=E2=80=AFAM Jonathan Wakely wrote: > > On Sat, 30 Mar 2024 at 06:12, NightStrike via Gcc-help > wrote: > > > > 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=3Dgnu++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. > > I don't think GNU C++ has any changes to the function declarator > syntax to support variably modified types. You can define a VLA > object, but you can't use earlier function parameters later in the > function-parameter-list, and you can't use int b[*] in a parameter > either. It looks like clang added support for this in v12. Maybe it would be a good candidate to add support? I guess I can file the PR and see where it lands. > > 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=3Dgnu++ mode (and it would be fine if it were > > rejected in -std=3Dc++ 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++?