struct A
{
auto g1()
{
return true;
}
void f()
{
if (auto b = g1(); b) // ok
{
return;
}
if (auto b = g2(); b) // error: use of 'auto A::g2()' before deduction of 'auto'
{
return;
}
}
auto g2()
{
return true;
}
};
Why does C++17 if statement with initializer not work as expected?
struct A { void f() { g2(); } auto g2() { } };
. The if-initializer is a red herring. – Retoolauto
deduction hasn't kicked in yet, because the function body isn't parsed yet. If you putg2
abovef
it works fine. – Implicative