On Fri, 27 Feb 2026 at 00:24, Yair Lenga via Gcc <[email protected]> wrote:
>
> Florian,
>
> Thanks for your suggestion. I'm already using macros, but that results
> in code that does not look like "C" any more. New "C" developers that
> are looking at hte code that uses DECLARE_VLA (or similar) macro -
> have trouble understanding this new construct, how to use it,
> limitations, etc (e.g., OK to use in `for (DECLARE_VLA(...) ; ; )`.
That doesn't have to be a problem:
#define ALLOW_VLA \
_Pragma("GCC diagnostic push"); \
_Pragma("GCC diagnostic ignored \"-Wvla\"")
#define DISALLOW_VLA \
_Pragma("GCC diagnostic pop")
ALLOW_VLA;
for (int vla[n]; ; )
...
DISALLOW_VLA;
That doesn't interfere with the declaration.
> The attribute provide "in-langauge" support for the same functionality
> in a way that is consistent with [[fallthru]], and similar.
C already allows in-language support for it, for 26 years now. If
somebody chooses to use -Wvla in non-C89 code, doesn't that mean they
actually want these warnings? The answer seems to be "don't do that
then". Adding an very narrowly focused attribute to say "don't warn
about this one very specific thing that we don't warn about anyway,
because it's valid C" seems like a very bad idea. Somebody has to
develop and test and maintain that attribute forever, for a very
narrow use case which is arguably just user error. Don't use -Wvla if
you want to compile code that uses VLAs.
Your original motivation says:
> However, there are occasional VLAs that are intentionally
> bounded/validated (e.g., small scratch buffers sized from known limits).
If it has a known limit, why not just use a constant as the bound, so
it's not a VLA at all?
And if it's only an occasional use, why is the existing pragma
solution so unusable? It already works, with all modern versions of
GCC.
That said, maybe adorning the declaration with __extension__ could
disable the warning. That would avoid needing a new attribute just for
this one warning.