0

当我有这样的函数模板时:

template<class T>
T func(T bar) {
    return bar;
}

我不能在最新的 MSVC 编译器的常量上下文中使用它的实例化:

constexpr bool b = std::is_function_v<decltype(func<int>)>; // fails with error C2131: expression did not evaluate to a constant
static_assert(std::is_compound_v<decltype(func<int>)>); // fails with C2057: expected constant expression

您可以在编译器资源管理器中自己测试它。

它适用于较旧的 MSVC 版本以及 GCC 和 Clang。它是编译器错误,还是预期的行为?

4

0 回答 0