From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CE5C8385840F; Sun, 8 May 2022 18:17:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CE5C8385840F From: "nunoplopes at sapo dot pt" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/105524] New: -Wmaybe-uninitialized false-positive with switch of enum with more than 2 elements Date: Sun, 08 May 2022 18:17:51 +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.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: nunoplopes at sapo dot pt 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 08 May 2022 18:17:51 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105524 Bug ID: 105524 Summary: -Wmaybe-uninitialized false-positive with switch of enum with more than 2 elements Product: gcc Version: 12.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: nunoplopes at sapo dot pt Target Milestone: --- The following program gets a false-positive when compiled with `-Wall -O3 -fstrict-enums`: // switch to 0 to make false-positive go away #define DEF_C 1 enum foo { A, B #if DEF_C , C #endif }; void g(const char*); void f(foo x) { const char *str; switch (x) { case A: str =3D "a"; break; case B: str =3D "b"; break; #if DEF_C case C: str =3D "c"; break; #endif } g(str); } https://gcc.godbolt.org/z/h1rWqezY3 : In function 'void f(foo)': :19:4: error: 'str' may be used uninitialized [-Werror=3Dmaybe-uninitialized] 19 | g(str); | ~^~~~~ :11:15: note: 'str' was declared here 11 | const char *str; | ^~~ cc1plus: all warnings being treated as errors Compiler returned: 1 The error only repros with enums with more than 2 elements.=