From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B42613858D3C; Wed, 1 Mar 2023 18:35:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B42613858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677695733; bh=yL8ex6u691i8uNJZhdF6LrZWT/psVzni9DZnWCM5ZVM=; h=From:To:Subject:Date:From; b=XUc5+FKZNSX8W2cm8GO1cAK+9LhVMA6p1qRvKziVKlAaNv+YqPRMWibjsLm8fuenK NXy6kzTmjKlDeER8y2s0YGT2ttO5x/HYx9Ry6iYiV+MSNh/FM3c+udz+0ckdDAQZtp BVGBNri6wrPNM6mJnAPe7y+5rkJ/cOpDxjyYauMY= From: "Keith.S.Thompson at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/108986] New: Incorrect warning for [static] array parameter Date: Wed, 01 Mar 2023 18:35:33 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: Keith.S.Thompson at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108986 Bug ID: 108986 Summary: Incorrect warning for [static] array parameter Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: Keith.S.Thompson at gmail dot com Target Milestone: --- When a parameter is declared with the (new in C99) [static] syntax, and the argument is a null pointer, the warning incorrectly refers to the expected size in bytes of the parameter rather than to its length. That by itself might be annoying but not incorrect, but the warning includes C syntax that is inconsistent with the actual declaration. (When the argument is an array object that's too short, the warning is different. It also refers to a size in bytes, and IMHO referring to the length would be clearer. Details to follow in a comment.) $ cat c.c #include void f(int a[static 7]) { } int main(void) { f(NULL); } $ gcc --version | head -n 1 gcc (GCC) 12.2.0 $ gcc -Wall -c c.c=20 c.c: In function =E2=80=98main=E2=80=99: c.c:6:5: warning: argument 1 to =E2=80=98int[static 28]=E2=80=99 is null wh= ere non-null expected [-Wnonnull] 6 | f(NULL); | ^~~~~~~ c.c:3:6: note: in a call to function =E2=80=98f=E2=80=99 3 | void f(int a[static 7]) { } | ^ c.c:6:5: warning: argument 1 to =E2=80=98int[static 28]=E2=80=99 is null wh= ere non-null expected [-Wnonnull] 6 | f(NULL); | ^~~~~~~ c.c:3:6: note: in a call to function =E2=80=98f=E2=80=99 3 | void f(int a[static 7]) { } | ^ $=