Closed
Description
Bugzilla Link | 51840 |
Version | trunk |
OS | Linux |
Reporter | LLVM Bugzilla Contributor |
CC | @dwblaikie,@zygoloid |
Extended Description
Reduced from https://stackoverflow.com/questions/69166564
The following code fails on clang >= 11.0 (including trunk)
consteval int f(int) { return 1; }
template
consteval bool g(T a)
{
int n = f(a); // error here
return true;
}
static_assert(g(2));
with
error: call to consteval function 'f' is not a constant expression
note: read of non-const variable 'a' is not allowed in a constant expression
This seems incorrect. The evaluation of f
is in an immediate context, i.e. inside g
so f(a)
should be a constant expression. Also, the error only appears if g
is a template, and if the result of f(a)
is stored in a local variable. GCC accepts the code.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done