-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
[consteval] clang++ sometimes reports false-positive errors for static consteval member functions #56246
Comments
@llvm/issue-subscribers-clang-frontend |
@llvm/issue-subscribers-c-2b |
@llvm/issue-subscribers-c-20 |
This does not work even for simpler cases of struct S {
static consteval int hello() { return 1;}
int foo() const {
return this->hello();
// ^ error: call to consteval function 'S::hello' is not a constant expression
// ^ note: use of 'this' pointer is only allowed within the evaluation of a call to a 'constexpr' member function
}
constexpr int bar() const {
return this->hello(); // same error and note as above.
}
consteval int baz() const {
// works fine.
return this->hello();
}
} s;
static_assert(s.baz() == 1); Clang errors and diverges from all the rest of the compilers. https://godbolt.org/z/93WTdbK1v |
9fcca8b#diff-f10defc3f20fb095bf22b3a79bead200d494bde9d503e283067a57aff483936c I think this patch fixed a crash but clang still produces an error. struct A {
consteval int a() const { return 1; }
void c() {
a() + d(); // expected-error {{call to consteval function 'PR48235::A::a' is not a constant expression}} \
// expected-note {{use of 'this' pointer is only allowed within the evaluation of a call to a 'constexpr' member function}}
} My reading of https://eel.is/c++draft/dcl.constexpr is that consteval members are valid and using them in any context (constant or unevaluated) show also be legal. Would be interested in knowing thoughts of @AaronBallman |
I believe http://eel.is/c++draft/expr.prim.id.general#4 is the cause of that diagnostic. https://godbolt.org/z/PP51G3WWW sure suggests everyone implements this the same way, too. |
Interesting. The above example looks right now. Coming back to struct S {
static consteval int hello() { return 1;}
int foo() const {
return this->hello();
// ^ error: call to consteval function 'S::hello' is not a constant expression
// ^ note: use of 'this' pointer is only allowed within the evaluation of a call to a 'constexpr' member function
}
constexpr int bar() const {
return this->hello(); // same error and note as above.
}
consteval int baz() const {
// works fine.
return this->hello();
}
} s;
static_assert(s.baz() == 1);
I guess clang is almost right but it should consider |
I think you're correct because of http://eel.is/c++draft/expr.const#5.1.2 specifically. While the So I think the diagnostic in |
I come to the conclusion that I agree with the rest of the conclusion ( |
Although I suspect I might be wrong again due to http://eel.is/c++draft/expr.prim.id.general#4. I am mostly confused about the definition of consteval int func() {return 0;}
struct S {
static consteval int hello() { return 1;}
int foo() const {
return this->hello(); // Why this should be invalid
// return func() ; // but this is valid. Both are core constant expressions!
}
} Is |
http://eel.is/c++draft/expr.post#expr.ref-6 determines what is denoted by the member access expression, and that |
Should be fixed by #63139 |
This currently working in trunk: https://godbolt.org/z/4P8GdPhWM |
When I have a CRTP that uses it's client's function, if that client's function happens to be
static consteval
,clang++
reports an error.live: https://godbolt.org/z/KG5oT6GTj
The text was updated successfully, but these errors were encountered: