public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/101289] New: bogus -Wvla-paramater warning when using const for vla param
@ 2021-07-01 21:45 ljrk at ljrk dot org
  2021-07-01 22:43 ` [Bug c/101289] " msebor at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: ljrk at ljrk dot org @ 2021-07-01 21:45 UTC (permalink / raw)
  To: gcc-bugs

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 ?

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-03-17 19:45 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-01 21:45 [Bug c/101289] New: bogus -Wvla-paramater warning when using const for vla param ljrk at ljrk dot org
2021-07-01 22:43 ` [Bug c/101289] " msebor at gcc dot gnu.org
2021-07-01 22:44 ` msebor at gcc dot gnu.org
2021-07-02  1:04 ` msebor at gcc dot gnu.org
2021-07-15 16:23 ` cvs-commit at gcc dot gnu.org
2021-07-15 16:25 ` msebor at gcc dot gnu.org
2021-07-23 19:44 ` [Bug c/101289] [11 Regression] " msebor at gcc dot gnu.org
2021-07-28  7:07 ` rguenth at gcc dot gnu.org
2021-12-16 22:47 ` cvs-commit at gcc dot gnu.org
2021-12-16 22:48 ` msebor at gcc dot gnu.org
2022-03-17 19:45 ` msebor at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).