首页 > 解决方案 > 带有 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()是否是一个有效的表达式。

标签: c++clangclang++llvm-clang

解决方案


推荐阅读