From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 344FE3858D3C; Fri, 9 Jun 2023 18:29:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 344FE3858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686335364; bh=m7bH8gBosnrl7yk2WlraIoXLmFFp/zgS3RzsE5NunLE=; h=From:To:Subject:Date:From; b=qzwDsU7UVdcv4aXQugtTgJEBQhayRVDDWH7V84JWnpYwPmTQL4KbB68FK8jnrqnX2 fCu/SSb73mrJKqN+0DAIGFnmcHONQwRiurbIaLFD8TaaN8RJfjDmX/U6Fp2lLFCWbA rQaoJaxIUCN74ZZ+2f/zjHFzC0nVEhRNqJftCnxk= From: "matt at godbolt dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/110197] New: Empty constexpr object constructor erronously claims out of range access Date: Fri, 09 Jun 2023 18:29:23 +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: 13.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: matt at godbolt dot org 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110197 Bug ID: 110197 Summary: Empty constexpr object constructor erronously claims out of range access Product: gcc Version: 13.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: matt at godbolt dot org Target Milestone: --- The following code, compiled on GCC 13.1 complains of a non-constexpr safe array access: ``` #include #include struct Currency { // commenting-in the `i` below fixes, as does passing a `const char *` = to the ctor // int i{}; constexpr explicit Currency(std::string_view name) {} // constexpr explicit Currency(const char *name) {} }; static Currency get_c() { static constexpr std::array c{Currency{"BWP"}}; return c[0]; } ``` The error is: ``` : In function 'Currency get_c()': :12:50: in 'constexpr' expansion of 'Currency(std::basic_string_view(((const char*)"BWP")))' :12:50: error: accessing uninitialized array element 12 | static constexpr std::array c{Currency{"BWP"}}; |=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20 ``` The same code compiles without issue on GCC 12.1, and on clang. Passing eit= her a const char * to the constructor, or adding a single field to the class ma= kes it compile. https://godbolt.org/z/G355frEM4 Was also reproducible on trunk as of 14da764809d3bffe9336e72999312ba3fb019d= c6=