<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61589>61589</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[concepts] Clang (11 to 16) crash when using generic lambda in template function
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
gracicot
</td>
</tr>
</table>
<pre>
I tried reducing as much as possible, but clang seems very fragile on reproducing this issue:
```c++
#include <type_traits>
#include <utility>
#include <concepts>
#define FWD(...) static_cast<decltype(__VA_ARGS__)&&>(__VA_ARGS__)
template<typename F, typename... Args>
concept callable = requires(F&& f, Args&&... args) {
FWD(f)(FWD(args)...);
};
template<typename T>
concept object = std::is_object_v<T>;
template<typename T>
concept constraint =
object<T>
and requires {
requires std::same_as<typename T::tag, void>;
};
struct member {
using tag = void;
};
template<typename>
struct specialize {};
template<typename, typename, typename>
inline constexpr bool callbale_with_nth_parameter_being_expand = false;
template<typename T, typename F, typename S>
inline constexpr bool callbale_with_nth_parameter_being_expand<
T, F,
specialize<S>
> = callable<
F,
T
>;
template<typename T, typename F, typename>
concept callbale_with_nth_parameter_being = callbale_with_nth_parameter_being_expand<
T, F,
specialize<int>
>;
template<typename... Args>
inline constexpr auto invoke_impl(
auto&& function,
Args... args
) -> decltype(auto) {
int arr[] = {0, callbale_with_nth_parameter_being<int, decltype(function), Args>...};
return FWD(function)(args...);
}
template<constraint... Args>
inline constexpr auto invoke(callable<Args...> auto&& function, Args... args) -> decltype(auto) {
return invoke_impl(FWD(function), args...);
}
struct my_type {
member a;
};
template<typename... Functions>
struct overload : Functions... {
using Functions::operator()...;
};
template<typename... Functions>
overload(Functions...) -> overload<Functions...>;
template<typename Type>
inline constexpr auto constructor() {
auto const call_constructor = overload{
[](int, auto&&... args) -> decltype(Type(FWD(args)...)) {
return Type(FWD(args)...);
},
[](void*, auto&&... args) -> decltype(Type{FWD(args)...}) {
return Type{FWD(args)...};
},
};
return [call_constructor](auto&&... args) -> decltype(call_constructor(0, FWD(args)...)) {
return call_constructor(0, FWD(args)...);
};
}
auto main() -> int {
invoke(constructor<my_type>(), member{});
}
```
Observations:
- Removing the `#include <utility>` will make clang go into infinite loop
- Changing `template<constraint... Args>` to `template<typename... Args>` will also make clang go into infinite loop
- Changing the `constaint` concept in any way seem to fix the crash.
- Changing the `callable<Args...> auto&& function` seems to fix the crash
- Changing the `callbale_with_nth_parameter_being_expand` variable to not be specialized seems to fix the crash
- Taking `auto const call_constructor = overload{...}` out of the `constructor` function seems to fix the crash
- Inlining the `object` concept into `constaint` seems to fix the crash
Let me know if more information is needed to fix this issue.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysWFFv6rgS_jXmxSoKToHwwEML5epIV7rSOdXdx8hJhuCtY2dthx7216_sOIlTKNCzp0IFYnvmm29mPttQrVkpANZo_ozm2wltzEGqdaloznJpJpksTutv2CgGBVZQNDkTJaYaV01-sO-11JplHBDZ4KwxOOdUlFgDVBofQZ3wXtGSccBSYAW1kt6EOTCNmdYNoPgJRVsUdf8XUfvKEXm2r_YpiZnIeVMARvHGnGpIjaLMaBS_XJrRGMaZOX0ymkuRQx0u7iYVsGcC8O6PLSLJdDpFZIW1oYblaU61QfGmgJxb_4gkafr_p_Tp-39-pCkiK0QW9hW_nI8EPgxUNacGfBSCVoB3lrzu23Q6xU-qHLB5sDinnNOM2wC2WMFfDVOgEUl2rWO8t1bcSvfd2qHu2wqjpafRB7Z3cJP2i5_UBovijvDldvj8KfLXM5Qy-xNy4zBqU9jcxk9Mp-3j9IjijVvzK6ZzKbRNunDmfUD-r7XfWe-HqCh6qgIW_F8_0iPVtIKU6g847IihpeX3KFkR4rdmzqnSRjW5wRVUGajAb6Nd6dPS8dPa-grffWzega4hZ5Szv8E5uctEUGqjz51pJrjtAEc2_KwVzqTkrvgyyiF9Z-aQCnNIa6poBQZUmgETZQo_a8u2DWxPuYa7Uh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