From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 39EFA3858C62; Sun, 25 Jun 2023 13:15:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 39EFA3858C62 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687698908; bh=/mm/aJdQsbFxgWdU5jeulRzGfhwz66+Boi8u5vPighU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=dLmhqk9RhfzdbRy2qyAf96nle/S6T7xW4LDtw7fhMgtMy2AS1dy10T7vlp3ELLdYf xsjyhearE30YaURmYkg8P0Ll+yi6Fuh01gEtvU75fBKzJjN0/lKliaKFEkMuqN9YeZ wksrWT2Jk4o85uMJ+8Ss9DG1nWY6Chf75/Q6Ucr4= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/110401] [10/11/12/13/14 Regression] Unhelpful "goto is not a constant expression" in ill-formed pre c++20 constexpr function template Date: Sun, 25 Jun 2023 13:15:07 +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: 14.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia 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: 10.5 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: short_desc cf_reconfirmed_on target_milestone bug_status cf_known_to_fail cf_known_to_work everconfirmed 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=3D110401 Andrew Pinski changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|Unhelpful "goto is not a |[10/11/12/13/14 Regression] |constant expression" in |Unhelpful "goto is not a |ill-formed pre c++20 |constant expression" in |constexpr function template |ill-formed pre c++20 | |constexpr function template Last reconfirmed| |2023-06-25 Target Milestone|--- |10.5 Status|UNCONFIRMED |NEW Known to fail| |7.3.0 Known to work| |7.1.0, 7.2.0 Ever confirmed|0 |1 --- Comment #1 from Andrew Pinski --- Compiling it with -std=3Dc++11 is even worse as it does not show the reason: ``` :12:36: error: 'constexpr std::array get_sqr() [with int N = =3D 10000]' called in a constant expression 12 | constexpr auto sqr =3D get_sqr<10000>(); | ~~~~~~~~~~~~~~^~ :4:30: note: 'constexpr std::array get_sqr() [with int N =3D 10000]' is not usable as a 'constexpr' function because: 4 | constexpr std::array get_sqr() | ^~~~~~~ ``` GCC 7.1 and 7.2 used to have the correct explanation for C++11+: ``` : In instantiation of 'constexpr std::array get_sqr() [with= int N =3D 10000]': :12:37: required from here :6:24: error: uninitialized variable 'ret' in 'constexpr' function std::array ret; ^~~ In file included from :1:0: /opt/compiler-explorer/gcc-7.2.0/include/c++/7.2.0/array:94:12: note: 'stru= ct std::array' has no user-provided default constructor struct array ^~~~~ /opt/compiler-explorer/gcc-7.2.0/include/c++/7.2.0/array:110:56: note: and = the implicitly-defined constructor does not initialize 'int std::array::_M_elems [10000]' typename _AT_Type::_Type _M_elems; ^~~~~~~~ :12:37: error: 'constexpr std::array get_sqr() [with int N = =3D 10000]' called in a constant expression constexpr auto sqr =3D get_sqr<10000>(); ^ :4:30: note: 'constexpr std::array get_sqr() [with int N =3D 10000]' is not usable as a constexpr function because: constexpr std::array get_sqr() ^~~~~~~ ``` GCC 7.3+ removed the "uninitialized variable 'ret' in 'constexpr' function". GCC 10+ then removed the 2 notes at the beginning. Note this is actually valid C++20 so maybe the change in GCC 10 is related = to that ...=