From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id F01353847801; Thu, 15 Apr 2021 00:14:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F01353847801 From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/99700] uninitialized variable accepted as a constant expression in C++ 20 Date: Thu, 15 Apr 2021 00:14:19 +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: 11.0 X-Bugzilla-Keywords: accepts-invalid X-Bugzilla-Severity: normal X-Bugzilla-Who: msebor at gcc dot gnu.org X-Bugzilla-Status: NEW 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: cc short_desc everconfirmed bug_status cf_reconfirmed_on 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 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: Thu, 15 Apr 2021 00:14:20 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99700 Martin Sebor changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |msebor at gcc dot gnu.org Summary|gcc takes an uninitialized |uninitialized variable |variable as a constant |accepted as a constant |expression |expression in C++ 20 Ever confirmed|0 |1 Status|UNCONFIRMED |NEW Last reconfirmed| |2021-04-15 --- Comment #1 from Martin Sebor --- Confirmed with -std=3Dc++20. In earlier modes GCC rejects the test case as expected. $ (set -x && gcc -O2 -S -Wall -std=3Dc++20 pr99700.C && gcc -O2 -S -Wall -std=3Dc++17 pr99700.C) + gcc -O2 -S -Wall -std=3Dc++20 pr99700.C + gcc -O2 -S -Wall -std=3Dc++17 pr99700.C pr99700.C: In constructor =E2=80=98constexpr A::A()=E2=80=99: pr99700.C:2:29: error: member =E2=80=98A::c=E2=80=99 must be initialized by= mem-initializer in =E2=80=98constexpr=E2=80=99 constructor 2 | constexpr A() { c[0] =3D 0; } | ^ pr99700.C:3:8: note: declared here 3 | char c[2]; | ^ pr99700.C: At global scope: pr99700.C:6:13: error: =E2=80=98constexpr A::A()=E2=80=99 called in a const= ant expression 6 | constexpr A a; | ^ pr99700.C:2:13: note: =E2=80=98constexpr A::A()=E2=80=99 declared here 2 | constexpr A() { c[0] =3D 0; } | ^ When reporting bugs please include all the information we ask for here: https://gcc.gnu.org/bugs/#need. Links to other sites are not a substitute.=