public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/114367] New: std::vector<bool> constexpr initialization doesn't start lifetime of array members
@ 2024-03-16 21:50 teodor_spaeren at riseup dot net
  2024-03-16 22:13 ` [Bug libstdc++/114367] " pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: teodor_spaeren at riseup dot net @ 2024-03-16 21:50 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-06-11 17:10 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-16 21:50 [Bug libstdc++/114367] New: std::vector<bool> constexpr initialization doesn't start lifetime of array members teodor_spaeren at riseup dot net
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

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).