https://bugs.llvm.org/show_bug.cgi?id=45506
Bug ID: 45506
Summary: Erroneous "if constexpr" instantiation in lambda
template
Product: clang
Version: trunk
Hardware: All
OS: All
Status: NEW
Severity: release blocker
Priority: P
Component: C++17
Assignee: unassignedclangb...@nondot.org
Reporter: le...@i42.co.uk
CC: blitzrak...@gmail.com, erik.pilking...@gmail.com,
llvm-bugs@lists.llvm.org, richard-l...@metafoo.co.uk
clang++ erroneously instantiates the "if constexpr" statement commented "pfft"
below; g++ and VS2019 accept it on local consensus is that it is a clang++ bug:
#include <cstdint>
#include <type_traits>
#include <variant>
#include <iostream>
template <typename T>
T foo(const std::variant<int64_t, double, std::string>& v)
{
T result;
std::visit([&result](auto&& a)
{
typedef std::decay_t<decltype(a)> vt;
if constexpr (std::is_same_v<vt, double>)
result = static_cast<T>(a);
else if constexpr (std::is_same_v<vt, int64_t>)
result = static_cast<T>(a);
else if constexpr (std::is_same_v<vt, std::string> &&
std::is_class_v<T>)
result = T::from_string(a); // pfft
else
throw std::logic_error("wibble");
}, v);
return result;
}
int main()
{
std::cout << foo<double>(int64_t{});
}
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs