Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
winner245 opened this issue Jan 6, 2025 · 0 comments · Fixed by #121848
Closed

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

winner245 opened this issue Jan 6, 2025 · 0 comments · Fixed by #121848
Assignees
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Comments

@winner245
Copy link
Contributor

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,

@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jan 6, 2025
@winner245 winner245 changed the title [libc++] vector<bool>::at() not as constexpr in libc++ [libc++] vector<bool>::at() not marked as constexpr in libc++ Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants