Open
Description
struct S {
static bool func2() { return func(); }
static consteval bool func() { return true; }
};
results in the diagnostic
<source>:4:32: error: call to consteval function 'S::func' is not a constant expression
4 | static bool func2() { return func(); }
| ^
<source>:4:32: note: undefined function 'func' cannot be used in a constant expression
<source>:6:25: note: declared here
6 | static consteval bool func() { return true; }
| ^
1 error generated.
The note is somewhat confusing IMO, since the consteval
function is in fact defined. Something like consteval function that has not yet been defined cannot be used
would be better, and an additional note consider moving the definition of `func` above `func2`
would be really great.
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
shafik commentedon Oct 9, 2023
I believe this is related to cwg1890, cwg2335, cwg1397 etc
At first it seems like expr.const p5.4:
but once we are in the body of member function we are in a complete class context and so then we should have a definition. All the issues I mentioned are various versions of that.
I posted to core and waiting for more feedback.
shafik commentedon Nov 14, 2023
See core discussion at: https://lists.isocpp.org/core/2023/10/14932.php
jwakely commentedon Nov 20, 2023
Is this why the following code fails with clang + libstdc++?
There's no consteval function here, but we get a similar
undefined function '_M_construct<const char *>' cannot be used in a constant expression
diagnostic about a member function defined outside the class body.tbaederr commentedon Nov 21, 2023
Shouldn't be a problem I think? https://godbolt.org/z/vcbcKK1Ez works, unless you swap lines 10 and 12.
cor3ntin commentedon Nov 27, 2023
@jwakely see #73232