相关疑难解决方法(0)

应该decltype(foo(1))实例化constexpr函数模板foo吗?

下面的代码使用gcc和MSVC进行编译,但是使用clang我用clang-3.5和当前主干测试失败了.

template <typename T>
constexpr auto wrong = false;

template <typename T>
constexpr auto foo(const T t) -> int
{
  static_assert(wrong<T>, "");
  return {};
}

using F = decltype(foo(1));

int main() {}
Run Code Online (Sandbox Code Playgroud)

clang实例化函数体并绊倒了static_assert.gcc和MSVC只是查看函数声明并忽略static_assert正文.

如果删除constexpr,所有编译器都可以编译代码.

问题:
如果声明了返回类型,是否允许decltype查看函数体?

我正在寻找标准中相应部分的参考.

c++ templates clang language-lawyer constexpr

9
推荐指数
1
解决办法
249
查看次数

标签 统计

c++ ×1

clang ×1

constexpr ×1

language-lawyer ×1

templates ×1