<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Erroneous "if constexpr" instantiation in lambda template"
href="https://bugs.llvm.org/show_bug.cgi?id=45506">45506</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Erroneous "if constexpr" instantiation in lambda template
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>release blocker
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++17
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>leigh@i42.co.uk
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>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{});
}</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>