class-static constexpr function not considered constexpt in vs c++ 17 when reference from template member
The following code does not compile with vs c++ 17 (vs2022) but does compile with c++ 15 (vs2017) and gcc10/11.
class X
{
public:
static constexpr bool constexprFoo()
{
return true;
}
template<class T>
T foo()
{
if constexpr (constexprFoo()) {}
return {};
}
}
1>TestConstexpr.cpp
1>C:\home\c\TestConstexpr\TestConstexpr.cpp(12,35): error C2131: expression did not evaluate to a constant
1>C:\home\c\TestConstexpr\TestConstexpr.cpp(12,35): message : failure was caused by call of undefined function or one not declared 'constexpr'
1>C:\home\c\TestConstexpr\TestConstexpr.cpp(12,35): message : see usage of 'X::constexprFoo'
1>C:\home\c\TestConstexpr\TestConstexpr.cpp(10,7): message : This diagnostic occurred in the compiler generated function 'T X::foo(void)'
1>Done building project "TestConstexpr.vcxproj" -- FAILED.
However, moving constexprFoo outside of the class or accessing it from a non-template member works fine.