Description
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.
#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,