https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122264
Bug ID: 122264
Summary: Incomplete error with nontrivial variable in consteval
function
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: blubban at gmail dot com
Target Milestone: ---
struct foo {
foo() {} // nontrivial
};
template<typename T>
consteval int bar(bool b)
{
if (b)
{
foo tmp;
}
return 5;
}
int baz()
{
return bar<int>(false);
}
-std=c++20
Result:
<source>: In function 'int baz()':
<source>:17:24: error: call to consteval function 'bar<int>(0)' is not a
constant expression
17 | return bar<int>(false);
| ~~~~~~~~^~~~~~~
<source>:17:24: error: 'consteval int bar(bool) [with T = int]' called in a
constant expression
<source>:6:15: note: 'consteval int bar(bool) [with T = int]' is not usable as
a 'constexpr' function because:
6 | consteval int bar(bool b)
| ^~~
Compiler returned: 1
Expected: Something to follow the 'because:' line. Maybe something like
<source>:10:21: error: variable 'tmp' of non-literal type 'foo' in 'constexpr'
function only available with '-std=c++23' or '-std=gnu++23'
(The line 17 "called in a constant expression" looks quite dubious too, but I
don't know enough standards terminology to determine if calling a consteval
function counts as a constant expression.)
https://godbolt.org/z/54nroE5K1
Reproduces on everything from 10.1 (9 doesn't support consteval at all) to
trunk-16.0.0-20251011-66a53767061d3f992f1e91fdd02ea7395636cdc8.