From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CC2973858D37; Sat, 12 Feb 2022 09:52:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CC2973858D37 From: "fchelnokov at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/104512] New: [c++20] consteval constructor does not need to initialize all data members Date: Sat, 12 Feb 2022 09:52:04 +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.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: fchelnokov 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 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: Sat, 12 Feb 2022 09:52:04 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104512 Bug ID: 104512 Summary: [c++20] consteval constructor does not need to initialize all data members Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: fchelnokov at gmail dot com Target Milestone: --- In the next program struct B has immediate consteval default constructor, w= hich does not initialize i field. Then this constructor is used to make a tempor= ary and its i field remains untouched: ``` struct B { bool b =3D true; int i; consteval B() {} }; static_assert( B{}.b ); ``` Clang and MSVC are fine with it. But GCC complains: error: 'B{true}' is not a constant expression 7 | static_assert( B{}.b ); | ^ error: 'B()' is not a constant expression because it refers to an incomplet= ely initialized variable Demo: https://gcc.godbolt.org/z/x4n6ezrhT The requirement that "every non-variant non-static data member must be initialized" in constexpr/consteval constructor is removed since c++20. Rel= ated discussion: https://stackoverflow.com/a/71085832/7325599=