[Bug c/101289] New: bogus -Wvla-paramater warning when using const for vla param
ljrk at ljrk dot org
gcc-bugzilla@gcc.gnu.org
Thu Jul 1 21:45:46 GMT 2021
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101289
Bug ID: 101289
Summary: bogus -Wvla-paramater warning when using const for vla
param
Product: gcc
Version: 11.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: ljrk at ljrk dot org
Target Milestone: ---
Created attachment 51099
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51099&action=edit
minimum working/reproducing example
If the vla parameter has a const specifier, the compiler will warn about
mismatched bounds:
$ cat mwe.c && make CFLAGS=-Wvla-parameter mwe.o
extern void mwe(const int len, char buf[len]);
void mwe(const int len, char buf[len]) {}
cc -Wvla-parameter -c -o mwe.o mwe.c
mwe.c:2:30: warning: argument 2 of type ‘char[len]’ declared with mismatched
bound ‘len’ [-Wvla-parameter]
2 | void mwe(const int len, char buf[len]) {}
| ~~~~~^~~~~~~~
mwe.c:1:37: note: previously declared as ‘char[len]’ with bound ‘len’
1 | extern void mwe(const int len, char buf[len]);
| ~~~~~^~~~~~~~
$
If I remove the const specifier to len, the warning goes away:
$ sed 's/const //g' -i mwe.c && make CFLAGS=-Wvla-parameter mwe.o
cc -Wvla-parameter -c -o mwe.o mwe.c
$
Maybe this is related to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97548 ?
More information about the Gcc-bugs
mailing list