Код: Выделить всё
#include
consteval auto func1()
{
return std::make_unique();
}
template
consteval auto func2()
{
[](auto) -> int {
func1();
return {};
}(0);
}
consteval auto func3()
{
func2();
}
Код: Выделить всё
:11:2: error: immediate function 'operator()' used before it is defined
11 | [](auto) -> int {
| ^
:11:2: note: in instantiation of function template specialization 'func2()::(anonymous class)::operator()' requested here
:19:2: note: in instantiation of function template specialization 'func2' requested here
19 | func2();
| ^
:11:2: note: 'operator()' defined here
11 | [](auto) -> int {
| ^
:12:3: note: 'operator()' is an immediate function because its body contains a call to a consteval function 'func1' and that call is not a constant expression
12 | func1();
| ^~~~~~~
- Переместите std::make_unique вызов func2
- Удалите завершающий тип возвращаемого значения () и вместо этого возвращайте int{}
Код: Выделить всё
-> int
- Удалите параметр auto, чтобы лямбда-оператор() не был шаблоном li>
Удалите шаблон , чтобы func2 не был шаблоном - Удалите consteval из func1
- Удалите consteval из func1
PS: эта ошибка появилась в каком-то коде с большим количеством шаблонов, который я написал, поэтому я потратил несколько часов, пытаясь найти этот минимально воспроизводимый пример. Если кто-то сможет найти лучший пример, дайте мне знать.
Подробнее здесь: https://stackoverflow.com/questions/792 ... mpiler-bug