c++ - 带有 is_invocable_v 的 clang++ 中的 ICE / 我的代码有效吗?
问题描述
以下代码无法使用 clang(核心转储/ICE)编译 - 但使用 gcc 和 msvc 可以正常编译。我的代码有效吗?我可以更改适用于当前 clang 版本的内容吗?
#include <type_traits>
#include <iostream>
struct A {
void Func() {
}
};
struct B {
static void Func() {
std::cout << "Hello from struct \n";
}
};
template<typename T>
void Do(){
auto lambda = [](auto&& cls) -> decltype(
std::remove_const_t<std::remove_reference_t<decltype(cls)>>::Func()
) {};
if constexpr (!std::is_invocable_v<decltype(lambda), A>){
std::cout << "no static Foo\n";
} else{
T::Foo();
}
}
int main()
{
Do<A>();
Do<B>();
return 0;
}
这段代码的想法是检测 exampleS::Func()
是否是一个有效的表达式。
解决方案
推荐阅读
- java - 如何获取栏顶部的数字
- c++ - 编译错误:临时对象构造函数中缺少参数
- matrix - 矩阵乘法返回不正确的结果 OpenCL
- javascript - 我怎么知道我需要哪个modernizr 部件?
- ruby-on-rails - 对于长别名,Rails 复合组计数失败。我怎样才能解决这个问题?
- teradata - 使用递归查询聚合周期
- javascript - 通过单击 contentEditable="false" 子节点来关注 contentEditable="true" 父节点
- react-native - React Native 动画在 iPhone X 上滞后
- python - 如何在python中填写插入语句的列名
- javascript - 放置在非活动手风琴容器中时,Dojo 小部件未正确呈现