llvm-project
llvm-project copied to clipboard
Frontend segfault on a trailing return type containing a constant-wrapper template (C++20)
Environment
Clang 19.1.0 (x86-64-unknown-linux-gnu, release build without assertions)
Command
$ clang++ -std=c++20 -pedantic-errors -c test8.cpp
Actual behavior
Segmentation fault: return-type deduction (DeduceAutoType) dereferences a null type pointer while instantiating the constant wrapper in the trailing return type.
Additional notes
The test case was produced by an automated compiler-testing tool (GapSmith).
Test case (test8.cpp)
template <auto V>
struct ConstantWrapper {
static constexpr auto value = V;
template <class... Ts>
constexpr auto operator()(Ts... args) const -> ConstantWrapper<value(Ts::value...)> {
return {};
}
};
struct Plus {
template <class T, class U>
constexpr auto operator()(T&& t, U&& u) const -> decltype(static_cast<T&&>(t) + static_cast<U&&>(u)) {
return static_cast<T&&>(t) + static_cast<U&&>(u);
}
};
constexpr auto cwv = ConstantWrapper<Plus{}>{}(ConstantWrapper<42>{}, ConstantWrapper<17>{});
@llvm/issue-subscribers-clang-frontend
Author: ICSE-27
## Environment
Clang 19.1.0 (x86-64-unknown-linux-gnu, release build without assertions)
Command
clang++ -std=c++20 -pedantic-errors -c test8.cpp
Actual behavior
Segmentation fault: return-type deduction (DeduceAutoType) dereferences a null type pointer while instantiating the constant wrapper in the trailing return type.
Additional notes
The test case was produced by an automated compiler-testing tool (GapSmith).
Test case (test8.cpp)
template <auto V>
struct ConstantWrapper {
static constexpr auto value = V;
template <class... Ts>
constexpr auto operator()(Ts... args) const -> ConstantWrapper<value(Ts::value...)> {
return {};
}
};
struct Plus {
template <class T, class U>
constexpr auto operator()(T&& t, U&& u) const -> decltype(static_cast<T&&>(t) + static_cast<U&&>(u)) {
return static_cast<T&&>(t) + static_cast<U&&>(u);
}
};
constexpr auto cwv = ConstantWrapper<Plus{}>{}(ConstantWrapper<42>{}, ConstantWrapper<17>{});