Unknown `this` pointer cannot be used in constant expressions where permitted by P2280R4
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
For the following code ([CE](https://godbolt.org/z/77h3cfjhr)):
```cpp
#include
template consteval auto size(const std::array &) {
return N;
}
struct S {
std::array a;
S() { constexpr auto n = ::size(a); }
};
```
MSVC and GCC accept it, as expected, but Clang rejects it with:
```cpp
:7:24: error: constexpr variable 'n' must be initialized by a constant expression
7 | S() { constexpr auto n = ::size(a); }
| ^ ~~~~~~~~~
:7:35: note: implicit use of 'this' pointer is only allowed within the evaluation of a call to a 'constexpr' member function
7 | S() { constexpr auto n = ::size(a); }
| ^
:7:28: error: call to consteval function 'size' is not a constant expression
7 | S() { constexpr auto n = ::size(a); }
| ^
:7:35: note: implicit use of 'this' pointer is only allowed within the evaluation of a call to a 'constexpr' member function
7 | S() { constexpr auto n = ::size(a); }
| ^
```
Is this a missed case in #63139?
Contributor guide
Assessment
This issue has not been assessed yet.