[PATCH] D156565: Diagnose use of VLAs in C++ by default
Nathan Chancellor via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 21 15:00:52 PDT 2023
nathanchance added a comment.
Is it expected that this introduces a warning for C code, as the commit message and tests appear to only affect C++? A trivial example from the Linux kernel:
https://elixir.bootlin.com/linux/v6.5.8/source/tools/lib/bpf/btf_dump.c#L1678
#include <stddef.h>
#include <stdio.h>
#include <string.h>
void foo(char *orig_name, char **cached_name, size_t dup_cnt)
{
const size_t max_len = 256;
char new_name[max_len];
snprintf(new_name, max_len, "%s___%zu", orig_name, dup_cnt);
*cached_name = strdup(new_name);
}
$ clang -std=gnu89 -Wall -fsyntax-only test.c
test.c:8:16: warning: variable length arrays are a C99 feature [-Wvla-extension]
8 | char new_name[max_len];
| ^~~~~~~
1 warning generated.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D156565/new/
https://reviews.llvm.org/D156565
More information about the cfe-commits
mailing list