Skip to content

[libc++] vector<bool>::at() not marked as constexpr in libc++ #121844

@winner245

Description

@winner245

The current implementation of vector<bool>::at() is not marked as constexpr in libc++, violating the C++20 standard, which requires all member functions of std::vector to be constexpr.

Godbolt Link

#include <vector>

constexpr bool test() {
    std::vector<bool> v{true, true, true};
    return v.at(0);
}

int main() {
    static_assert(test());
    return 0;
}

The above code fails to compile in libc++, with the following error message:

<source>:9:19: error: static assertion expression is not an integral constant expression
    9 |     static_assert(test());
      |                   ^~~~~~
<source>:5:14: note: non-constexpr function 'at' cannot be used in a constant expression
    5 |     return v.at(0);

We should mark the vector<bool>::at() member function as constexpr in libc++ to ensure compliance with the C++20 standard,

Metadata

Metadata

Assignees

Labels

libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions