You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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;
ifconstexpr (std::is_same_v<vt, double>)
result = static_cast<T>(a);
elseifconstexpr (std::is_same_v<vt, int64_t>)
result = static_cast<T>(a);
elseifconstexpr (std::is_same_v<vt, std::string> && std::is_class_v<T>)
result = T::from_string(a); // pfftelsethrowstd::logic_error("wibble");
}, v);
return result;
}
intmain()
{
std::cout << foo<double>(int64_t{});
}
The text was updated successfully, but these errors were encountered:
template <typename T> intfoo() {
int ans;
auto &&x = [&ans](auto a) {
ifconstexpr (sizeof(double) != sizeof a)
ans = sizeof(T::type);
};
x(0.);
return ans;
}
intmain() {
foo<double>();
}
ICC produces an error similar to Clang's.
The question is whether or not instantiation of foo<double> needs to defer substitution into the subexpression of the constexpr-if or accept formation of impossible types.
This code is only valid after the resolution of http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0588r1.html, which Clang does not yet implement. Prior to that change, instantiation of a generic lambda in general requires full substitution into the body of the lambda in order to determine the set of captures.
Note, however, that P0588R1 was accepted into C++ as a defect report resolution, so Clang will apply it retroactively to all language modes when it is implemented.
Endilll
changed the title
Erroneous "if constexpr" instantiation in lambda template
Erroneous if constexpr instantiation in lambda template
Jul 19, 2024
Extended Description
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:The text was updated successfully, but these errors were encountered: