From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DD8EE3858434; Wed, 17 May 2023 10:15:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DD8EE3858434 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684318510; bh=JaPSXPT+H703U2uxjlQ2ZZ+omU155PD2CXukjjEOfJo=; h=From:To:Subject:Date:From; b=Xpci08i00Heo64zQxeAocqUJyNU46By40SwCilKrPU4e0iTj8wtHRq1hX712nfWMo lOiJaGSoX+CSiS1POK0XjfFi25Red+IAG4mzRN4S9aaIuWN260M+TeBqZp3dQyNeM7 g2xo/XLVruuq5PTRb7BJHNx5jXJyr3G9LBV2o1BQ= From: "vincent.lebourlot at starqube dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/109888] New: GCC 13 Fails to Compile Code with Explicit Constructor for std::array in Template Class Date: Wed, 17 May 2023 10:15:10 +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: vincent.lebourlot at starqube 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109888 Bug ID: 109888 Summary: GCC 13 Fails to Compile Code with Explicit Constructor for std::array in Template Class Product: gcc Version: 13.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: vincent.lebourlot at starqube dot com Target Milestone: --- In a C++ codebase, a class String is defined with an explicit constructor t= hat takes a variable number of arguments and constructs a std::array from them. This constructor is being called when creating a std::pair = in a function call. While this code compiles successfully with GCC 12, it fails to compile with= GCC 13. The error messages indicate that the std::array must be initialized wit= h a brace-enclosed initializer, which is not what's happening when forwarding t= he arguments to the std::array's constructor. This issue seems to be specific to GCC 13 and does not occur in GCC 12. It's unclear whether this is due to changes in the C++ standard or in GCC's implementation of the standard. The code snippet that reproduces this issue= is provided below: #include #include #include #include #include class String { public: templateString(const char(&s)[n])noexcept:value(){ if constexpr(n<=3D16){ std::memcpy(value.data(),s,n);} else{value=3Dstd::array{};}} template...>, int> =3D 0> explicit String(Args&&... args) : value(std::forward(args)...) {} private: std::arrayvalue; }; int main() { auto check=3D[&](std::vector>textInputs){}; check({{{"Hello", "World"}, {"Foo", "Bar"}}}); return 0; } And here's the error message: test.cpp: In function =E2=80=98int main()=E2=80=99: test.cpp:20:10: error: converting to =E2=80=98const String=E2=80=99 from in= itializer list would use explicit constructor =E2=80=98String::String(Args&& ...) [with Args =3D= {const char (&)[6], const char (&)[6]}; typename std::enable_if, std::allocator >, Args>...>, int>::type =3D 0]=E2=80=99 20 | check({{{"Hello", "World"}, {"Foo", "Bar"}}}); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ test.cpp:20:10: error: converting to =E2=80=98const String=E2=80=99 from in= itializer list would use explicit constructor =E2=80=98String::String(Args&& ...) [with Args =3D= {const char (&)[4], const char (&)[4]}; typename std::enable_if, std::allocator >, Args>...>, int>::type =3D 0]=E2=80=99 test.cpp: In instantiation of =E2=80=98String::String(Args&& ...) [with Arg= s =3D {const char (&)[6], const char (&)[6]}; typename std::enable_if, std::allocator >, Args>...>, int>::type =3D 0]=E2=80=99: test.cpp:20:10: required from here test.cpp:12:39: error: no matching function for call to =E2=80=98std::array= ::array(const char [6], const char [6])=E2=80=99 12 | explicit String(Args&&... args) : value(std::forward(args)...) {} |=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 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from test.cpp:3: /usr/local/gcc/gcc-13/include/c++/13.1.0/array:94:12: note: candidate: =E2=80=98std::array::array()=E2=80=99 94 | struct array | ^~~~~ /usr/local/gcc/gcc-13/include/c++/13.1.0/array:94:12: note: candidate exp= ects 0 arguments, 2 provided /usr/local/gcc/gcc-13/include/c++/13.1.0/array:94:12: note: candidate: =E2=80=98constexpr std::array::array(const std::array&)=E2=80=99 /usr/local/gcc/gcc-13/include/c++/13.1.0/array:94:12: note: candidate exp= ects 1 argument, 2 provided /usr/local/gcc/gcc-13/include/c++/13.1.0/array:94:12: note: candidate: =E2=80=98constexpr std::array::array(std::array&&)=E2=80=99 /usr/local/gcc/gcc-13/include/c++/13.1.0/array:94:12: note: candidate exp= ects 1 argument, 2 provided test.cpp: In instantiation of =E2=80=98String::String(Args&& ...) [with Arg= s =3D {const char (&)[4], const char (&)[4]}; typename std::enable_if, std::allocator >, Args>...>, int>::type =3D 0]=E2=80=99: test.cpp:20:10: required from here test.cpp:12:39: error: no matching function for call to =E2=80=98std::array= ::array(const char [4], const char [4])=E2=80=99 12 | explicit String(Args&&... args) : value(std::forward(args)...) {} |=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 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/local/gcc/gcc-13/include/c++/13.1.0/array:94:12: note: candidate: =E2=80=98std::array::array()=E2=80=99 94 | struct array | ^~~~~ /usr/local/gcc/gcc-13/include/c++/13.1.0/array:94:12: note: candidate exp= ects 0 arguments, 2 provided /usr/local/gcc/gcc-13/include/c++/13.1.0/array:94:12: note: candidate: =E2=80=98constexpr std::array::array(const std::array&)=E2=80=99 /usr/local/gcc/gcc-13/include/c++/13.1.0/array:94:12: note: candidate exp= ects 1 argument, 2 provided /usr/local/gcc/gcc-13/include/c++/13.1.0/array:94:12: note: candidate: =E2=80=98constexpr std::array::array(std::array&&)=E2=80=99 /usr/local/gcc/gcc-13/include/c++/13.1.0/array:94:12: note: candidate exp= ects 1 argument, 2 provided=