On Mon, Feb 23, 2026 at 11:31 AM Yair Lenga via Gcc <[email protected]> wrote:
>
> Hi GCC maintainers,
>
> I’d like feedback on a small, C-only attribute proposal to improve
> practicality of using -Wvla in large codebases.
> Motivation

The only thing I am going to say is this should NOT be C only because
the C++ front-end support VLA as an extension.

Thanks,
Andrew


>
> Projects often enable -Wvla (sometimes with -Werror=vla) to discourage
> unbounded VLAs. However, there are occasional VLAs that are intentionally
> bounded/validated (e.g., small scratch buffers sized from known limits).
> Today, suppressing -Wvla locally requires #pragma GCC diagnostic
> push/ignored/pop, which is verbose and harder to keep correct during
> refactoring.
>
> I’m looking for a declaration-scoped, readable opt-out similar in spirit to
> [[fallthrough]]: keep the warning enabled globally, but allow a
> clearly-marked exception at a specific declaration.
> Proposal (C only)
>
> Introduce a GNU C attribute:
>
> [[gnu::allow_vla]] char tmp[n];
>
> (Spelling is flexible; I mainly want the functionality. I’m fine with
> __attribute__((allow_vla)) as well, but [[gnu::...]] is pleasant in C23
> style.)
> Semantics
>
> When -Wvla is enabled, a VLA declaration annotated with [[gnu::allow_vla]]
> does *not* emit the -Wvla warning for that declaration.
>
> Non-goals:
>
>    -
>
>    No change to VLA semantics, ABI, or code generation.
>    -
>
>    Not a general “suppress any warning” attribute.
>    -
>
>    C-only (no C++ support requested).
>
> Scope restrictions (to reduce ambiguity)
>
> I suggest restricting the attribute to:
>
>    -
>
>    object declarations with automatic storage duration (typical VLA usage),
>    and
>    -
>
>    only affecting the -Wvla diagnostic for that declaration.
>
> (If maintainers prefer broader applicability, I can adjust, but I’d like to
> start minimal.)
> Implementation sketch
>
> My assumption is:
>
>    -
>
>    parse/attach the attribute to the relevant DECL (e.g., DECL_ATTRIBUTES),
>    -
>
>    and gate the -Wvla diagnostic emission on “decl has allow_vla”.
>
> I can provide a patch + tests once there is agreement on direction and
> naming.
> Questions
>
>    1.
>
>    Is a dedicated C-only GNU attribute acceptable for this purpose, vs.
>    insisting on #pragma GCC diagnostic?
>    2.
>
>    Preferred spelling/name: allow_vla, vla_ok, etc.?
>    3.
>
>    I intentionally propose -Wvla suppression only; I’m not requesting
>    suppression of -Wvla-larger-than=.
>
> Thanks,
> Yair

Reply via email to