【发布时间】:2017-07-06 12:41:47
【问题描述】:
以下声明在 clang 3.8.1 中失败,但似乎在其他经过测试的编译器中编译没有错误(例如 gcc 6.1、MSVC 2015、clang 3.9.1)。
constexpr std::integral_constant<int,0> myConstant;
clang 3.8.1 给出:
error: default initialization of an object of const type 'const std::integral_constant<int, 0>' without a user-provided default constructor constexpr std::integral_constant<int,0> myConstant;
而以下在所有测试的编译器中都正确编译:
constexpr std::integral_constant<int,0> myConstant = {};
这里发生了什么? (clang 3.8.1的错误正确吗?)
如果我定义自己的类型,我是否应该编写一个用户提供的默认 ctor 以便用户可以避免输入 ={} ?
【问题讨论】:
标签: c++11