<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/121844>121844</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[libc++] `vector<bool>::at()` not as constexpr in libc++
</td>
</tr>
<tr>
<th>Labels</th>
<td>
libc++
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
winner245
</td>
</tr>
</table>
<pre>
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](https://godbolt.org/z/Ejc38hMzK)
```cpp
#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,
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMVM2O6zYPfRp5Q0wgS_5deJFkJt_ia3cFuixkmYl1ryylkpxp76LPXtBOJvNzpxhBiBSIpA8PD6liNCeH2LFyx8rHTM1p9KF7Ns5hEEWZ9X74u_ttRNBzCOgSmOlscUKXVDLegT8Cq_gFdfKByX3vvWXyicktk1uVmGiYaFnFwURwPsGkwnccQEXQ3sWEf50DGAfW9JqJ3bL3cDHeqmTcCdKIsF8fBIeYlBtUGMjmeTR6hIB_ziZgBGUtTDj1GOA4O03Q4hVbTMMK5wqy4pA89HhHsAHGt7TL3f_80Hub4BfjvrPykYlmTOkcKYA4MHE4re8bH05MHH4wcXj6pmUz_vrj_5ToGqbi69bnM_0V0jht5wGByf2NqafV9s4CMQcJ45UzYPWO8S0AwPsEXliGC6t3KcxIhLw560cmb-4B0xwcXDZLOTjBXN7IaMFgHNXFuJ98WCWj_1AxYiDfO7qXILfo_E3MGwFrfFKP6v2FGB8QjsrYSCXQfjobix_r_2zSuJT-6K31zyQEDMEHmDBGdUJi4y3TdJf76OegcZVfy-Q2p5_VlS5rOrCmQ9ol3jFGul7lqRwYl_AUlF3loVx6ZXblhTjaf4mdZZHxx8XKp39ofYReEvSCEDufcD3dw10pN4EDEzXVtAatHKHvEeaIAxGqPoNfvsD5VBdvq_c7Qhz9bIeld5eyfKnh33Xjf7Q8aQFdnAMukrBGOY13Efy8_7Ohk0MrW5Vhl9eyEpw3VZuNXSGOg2xFVQ19I0WuWsmx4WUjiibnZdFmphNclDznlRA85_WGS1ljUbRiKHWb15oVHCdl7Mbay0SdnpkYZ-xykTdFkVnVo43LwBTitXAFDdDQkddDP58iK7g1McV7nGSSXUbtK7fy8Wt8LvL8lMNsDrZ7N6pMGud-o_3ExIEgXI-Hc_DfUCcmDktekYnDNbVLJ_4NAAD__-o-1_A">