RFC (C only): [[gnu::allow_vla]] attribute to suppress -Wvla on a single declaration

David Brown david.brown@hesbynett.no
Tue Feb 24 10:00:54 GMT 2026


On 23/02/2026 20:30, Yair Lenga via Gcc 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
> 
> 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.

OK.

>     -
> 
>     Not a general “suppress any warning” attribute.
>     -

Why not?

> 
>     C-only (no C++ support requested).
> 

Why?


How about introducing new attributes:

	[[gnu::diagnostic_ignored("-Wvla")]]
	[[gnu::diagnostic_warning("-Wvla")]]
	[[gnu::diagnostic_error("-Wvla")]]

such that writing

	[[gnu::diagnostic_ignored("-Wvla")]] char tmp[n];

would have the same effect as

	#pragma GCC diagnostic push
	#pragma GCC diagnostic ignored "-Wvla"
	      char tmp[n];
	#pragma GCC diagnostic pop

?

That is, rather than making a single attribute for a single warning, 
make a general attribute (or three general attributes) that work for any 
warning.  The potential benefits would be vastly greater, even though it 
might involve a bit more work in implementation.  It would certainly be 
less work than adding (and documenting!) similar attributes for a range 
of other warnings.  From a quick check in a recent project, I've used 
the push/ignored/pop pattern for -Wpadded, -Wcast-align and 
-Wfloat-equal.  And if it is of interest to have attributes for 
temporarily disabling more than one warning type, having a consistent 
naming that follows the warning flag is hugely better than ad-hoc names 
like "allow_vla", "might_be_padded", "cast_unaligned", 
"compare_float_equal".



For just this on-off case, I am not sure I see how useful such an 
attribute would be compared to just defining a macro :

#define ALLOW_VLA(decl) \
     _Pragma("GCC diagnostic push") \
     _Pragma("GCC diagnostic ignored \"-Wvla\"") \
     decl; \
     _Pragma("GCC diagnostic pop")

And then writing "ALLOW_VLA(char tmp[n]);"


David















More information about the Gcc mailing list