From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C448C3858D32; Tue, 2 Jan 2024 15:41:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C448C3858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1704210105; bh=JdBwZ8Y/gwzTDKq3lzYTK1vV9U6W777hbDbLW3Q9PlM=; h=From:To:Subject:Date:From; b=N4vzZemE8sDgkFyGmRCpYG/qJIpuDyoxXmNkxGC68PpVRhPbOT0TfWRfPy5J8D2GK uX9JeqDwL59/8BjAZ/I9L2sSqK0dLX1u4v25iWB2SLb+dY+QRl9TEzUlUHFnVb+/Os M5nikMI07vMiMm6wktmudrLS3j1AG4m6+/11cWRY= From: "pdimov at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/113200] New: std::char_traits::move is not constexpr when the argument is a string literal Date: Tue, 02 Jan 2024 15:41:44 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 13.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: pdimov 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D113200 Bug ID: 113200 Summary: std::char_traits::move is not constexpr when the argument is a string literal Product: gcc Version: 13.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: pdimov at gmail dot com Target Milestone: --- ``` #include #include template struct S { char data_[ N ]; using traits_type =3D std::char_traits; constexpr S( char const* p ): data_{} { std::size_t n =3D traits_type::length( p ); assert( n < N ); traits_type::move( data_, p, n + 1 ); } }; template S( char const(&)[N] ) -> S; constexpr S s( "test" ); ``` (https://godbolt.org/z/PofY8MP6G) fails with ``` In file included from /opt/compiler-explorer/gcc-trunk-20240102/include/c++/14.0.0/string:42, from :1: :22:23: in 'constexpr' expansion of 'S<5>(((const char*)"test"))' :16:26: in 'constexpr' expansion of 'std::char_traits::move(((char*)(&((S<5>*)this)->S<5>::data_)), p, (n= + 1))' /opt/compiler-explorer/gcc-trunk-20240102/include/c++/14.0.0/bits/char_trai= ts.h:423:50: in 'constexpr' expansion of '__gnu_cxx::char_traits::move(__s1, __s= 2, __n)' /opt/compiler-explorer/gcc-trunk-20240102/include/c++/14.0.0/bits/char_trai= ts.h:230:20: error: '(((const __gnu_cxx::char_traits::char_type*)(& s.S<5>::data_)= ) =3D=3D ((const char*)"test"))' is not a constant expression 230 | if (__s1 =3D=3D __s2) // unlikely, but saves a lot of work | ~~~~~^~~~~~~ ``` (Reduced from a similar failure in Boost.StaticString.)=