Description
Bugzilla Link | 35704 |
Version | trunk |
OS | Windows NT |
Attachments | sample cpp file |
Reporter | LLVM Bugzilla Contributor |
Extended Description
When constexpr lambda used in constant expression it going non constant when its parameter is auto.
In this sample got an error:
1> ConsoleApplication1.cpp(20,16): error : constexpr if condition is not a constant expression
1> if constexpr (f(TypeTag::value))
1> ^~~~~~~~~~~~~~~~~~~~
But if
auto predicate = [](auto v) constexpr -> bool
replaced by
auto predicate = [](size_t v) constexpr -> bool
all ok.
#include
template
struct TypeTag
{
constexpr static size_t value = 1;
};
template<>
struct TypeTag
{
constexpr static size_t value = 2;
};
template<typename T, typename F>
constexpr auto func(F f)
{
if constexpr (f(TypeTag::value))
{
return int{1};
}
else
{
return float{2.2f};
}
}
int main()
{
auto predicate = [](auto v) constexpr -> bool // does not compile when v is auto
{
return v == 1;
};
constexpr auto ok = predicate(75);
constexpr auto fail = func<int>(predicate);
return 0;
}