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.