From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 600F93858D35; Fri, 11 Nov 2022 05:01:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 600F93858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668142899; bh=DGcQMTbr0xiLIc0Qq4JIDkXWESzzVDj1uGSqmdZ/gq8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=sz9Sy28wpjySKXSWfI1G9Tuf+iKLZKnEDPBrIPmppbQ7obwpCFPWccEysuC7IKK0L YKA6kU5udHOiZudKT79Ze4I5E/9omRd4WVKXoeT8tFlAuvPfYvLe6Gufdseu4nD+RH WUfbbwvm/ZfyDiirjblAkax97DC2GbouY0n5Nva0= From: "klaus.doldinger64 at googlemail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/107622] Missing optimization of switch-statement Date: Fri, 11 Nov 2022 05:01:39 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: klaus.doldinger64 at googlemail 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: Message-ID: In-Reply-To: References: 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=3D107622 --- Comment #4 from Wilhelm M --- In the following class the static data member is accessible via explicit template instantiation from the outside. So the compiler cannot reason that= the value is in [0,2]. But this does not hold for the function g(): here mState= 2 is definitely not accessible from outside. But here the std::unreachable() is still neccessary. here the optimization is missing.=20 struct FSM { enum class State : uint8_t {A, B, C}; static void f() { switch(mState) { case State::A: o =3D 10; break; case State::B: o =3D 11; break; case State::C: o =3D 12; break; default: // std::unreachable(); break; } } static void g() { static State mState2{State::A}; // not accessible from outside switch(mState2) { case State::A: o =3D 10; break; case State::B: o =3D 11; break; case State::C: o =3D 12; break; default: // std::unreachable(); break; } } private: inline static State mState{State::A}; // still modifyable via explicit template instantiation };=