From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3909F385842E; Sat, 16 Mar 2024 21:50:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3909F385842E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1710625845; bh=bPA0Ca5pcIXNJrS+thPPGr511fV8rRQANFaIZSPUznw=; h=From:To:Subject:Date:From; b=lxmPOrhEubpBE2nf184HP7llYLyOnWug5ZKF9sjjTNhQs2T3VnK1cDB1Pz8ead9YV 6/bIfjDCu04CridziifTEHddF2TB2VAAE8senwSCRaI8VXKUioG47LZsLXZa4MHd4z 6H44dwZRhJoks7a6VqQzviC3Hp7Y5sqQ4ijEwZJ8= From: "teodor_spaeren at riseup dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/114367] New: std::vector constexpr initialization doesn't start lifetime of array members Date: Sat, 16 Mar 2024 21:50: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.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: teodor_spaeren at riseup dot net 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=3D114367 Bug ID: 114367 Summary: std::vector constexpr initialization doesn't start lifetime of array members Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: teodor_spaeren at riseup dot net Target Milestone: --- #include consteval int foo(){ std::vectorseen(26); return 0; } int main(){ return foo(); } This is the code. If you compile this with g++, it compiles fine, but with clang it gives a warning about object lifetimes. lel.cpp:7:12: error: call to consteval function 'foo' is not a constant expression return foo(); ^ /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../include/c++/13= .2.1/bits/stl_bvector.h:649:15: note: assignment to object outside its lifetime is not allowed in a constant expression __p[__i] =3D 0ul; ^ /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../include/c++/13= .2.1/bits/stl_bvector.h:1317:31: note: in call to '&seen->_M_allocate(1)' _Bit_pointer __q =3D this->_M_allocate(__n); ^ /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../include/c++/13= .2.1/bits/stl_bvector.h:768:2: note: in call to '&seen->_M_initialize(26)' _M_initialize(__n); ^ /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../include/c++/13= .2.1/bits/stl_bvector.h:755:9: note: in call to 'vector(26, false, allocator_type())' : vector(__n, false, __a) ^ lel.cpp:3:22: note: in call to 'vector(26, allocator_type())' std::vectorseen(26); ^ lel.cpp:7:12: note: in call to 'foo()' return foo(); ^ 1 error generated. When compiling with=20 https://github.com/gcc-mirror/gcc/blob/releases/gcc-13/libstdc%2B%2B-v3/inc= lude/bits/stl_bvector.h#L676-L685 In the code it seems it never constructs the array, but starts accessing the members directly. I don't know if this is affected by https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p0593r6.html or no= t. I've submitted a bug report to clang also.=