在为操作员()显式指定模板参数时,对Clang前端ICE的C ++快速修复? [英] C++ quickfix to Clang frontend ICE when explicitly specifying template parameter to operator()?
本文介绍了在为操作员()显式指定模板参数时,对Clang前端ICE的C ++快速修复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
- 关于LLVM错误报告的已报告问题: https://bugs.llvm.org/show_bug.cgi?id = 49881
考虑以下最小再现案例:
Considering the following minimal reproduction case example :
#include <tuple>
int main()
{
// KO, explicit template parameter
const auto lambda_1 = []<typename T>(){};
[&lambda_1]<typename ... Ts>(std::tuple<Ts...>){
((lambda_1.template operator()<Ts>()), ...);
}(std::tuple<int>{});
// OK, template deduced using parameter
const auto lambda_2 = []<typename T>(T){};
[&lambda_2]<typename ... Ts>(std::tuple<Ts...>){
((lambda_2(Ts{})), ...);
}(std::tuple<int>{});
}
这里的问题是,这样的解决方案要求 Ts ...
是默认可构造的.
The issue here is, that such solution requires Ts...
to be default constructible.
因此,它不适用于非类型,例如带有存储的lambda,
例如:
Thus, it does not work with types which are not, such as lambdas with storage,
for instance :
// KO, Ts... is not default constructible
const auto lambda = []<typename T>(T){};
int i{0};
[&lambda]<typename ... Ts>(std::tuple<Ts...>){
((lambda(Ts{})), ...);
}(std::tuple{
[i]() {}
});
问题:
- 我们是否应谴责暂时禁用对项目的Clang支持,并等待补丁,
还是在下一个版本(将修复此ICE的版本)之前,我们可以使用任何快速修复程序进行这项工作? - Are we condemned to temporarily disable Clang support to our projects, and wait for a patch,
or is there any quick-fix we can use to make this work until the next release(s) (that will fix this ICE) ?
Question :
推荐答案
"struct可能有助于传递类型并允许推导:
A "tag" struct might help to pass type and allow deduction:
template <typename T>
struct Tag
{
using type = T;
};
// or
// template <typename T> using Tag = std::type_identity<T>;
然后而不是:
const auto lambda_1 = []<typename T>(){/*...*/};
lambda_1.template operator()<SomeT>();
您可能有:
const auto lambda_2 = []<typename T>(Tag<T>){ /*...*/};
lambda_2(Tag<SomeT>{});
// C++14: No constraints on tag
const auto lambda_3 = [](auto tag){ using T = typename decltype(tag)::type; /*...*/ };
lambda_3(Tag<SomeT>{});
这篇关于在为操作员()显式指定模板参数时,对Clang前端ICE的C ++快速修复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文