public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "teodor_spaeren at riseup dot net" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/114367] New: std::vector<bool> constexpr initialization doesn't start lifetime of array members Date: Sat, 16 Mar 2024 21:50:44 +0000 [thread overview] Message-ID: <bug-114367-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114367 Bug ID: 114367 Summary: std::vector<bool> 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<vector> consteval int foo(){ std::vector<bool>seen(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] = 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 = 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::vector<bool>seen(26); ^ lel.cpp:7:12: note: in call to 'foo()' return foo(); ^ 1 error generated. When compiling with https://github.com/gcc-mirror/gcc/blob/releases/gcc-13/libstdc%2B%2B-v3/include/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 not. I've submitted a bug report to clang also.
next reply other threads:[~2024-03-16 21:50 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-03-16 21:50 teodor_spaeren at riseup dot net [this message] 2024-03-16 22:13 ` [Bug libstdc++/114367] " pinskia at gcc dot gnu.org 2024-03-16 22:14 ` pinskia at gcc dot gnu.org 2024-03-17 9:15 ` redi at gcc dot gnu.org 2024-03-18 13:19 ` redi at gcc dot gnu.org 2024-03-19 15:14 ` cvs-commit at gcc dot gnu.org 2024-04-03 10:46 ` cvs-commit at gcc dot gnu.org 2024-06-11 17:06 ` cvs-commit at gcc dot gnu.org 2024-06-11 17:10 ` redi at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-114367-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).