llvm / llvm/llvm-project

Unknown `this` pointer cannot be used in constant expressions where permitted by P2280R4

Open
#191,104 3 comments 0 reactions 0 assignees View on GitHub
clang:frontend constexpr diverges-from:gcc diverges-from:msvc
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.