在 gcc 中使用大括号初始值设定项初始化成员 std::array 时出错

Error when initializing a member std::array with a brace initializer in gcc

考虑以下示例:

#include <array>

template <typename T>
struct A {
  A() {}
};

typedef A<int> B;

struct S {
  std::array<B, 1> b;

  S() : b{{B()}} {}
};

int main() {
  S s;
}

当尝试用 g++ 4.6.3 和 -std=c++0x 编译它时,我得到这个错误:

test.cc: In constructor ‘S::S()’:
test.cc:13:16: error: no matching function for call to ‘std::array<A<int>, 1ul>::array(<brace-enclosed initializer list>)’
test.cc:13:16: note: candidates are:
/usr/include/c++/4.6/array:60:12: note: std::array<A<int>, 1ul>::array()
/usr/include/c++/4.6/array:60:12: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/4.6/array:60:12: note: constexpr std::array<A<int>, 1ul>::array(const std::array<A<int>, 1ul>&)
/usr/include/c++/4.6/array:60:12: note:   no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘const std::array<A<int>, 1ul>&’
/usr/include/c++/4.6/array:60:12: note: constexpr std::array<A<int>, 1ul>::array(std::array<A<int>, 1ul>&&)
/usr/include/c++/4.6/array:60:12: note:   no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘std::array<A<int>, 1ul>&&’

然而,同样的大括号初始化在定义变量时起作用:

std::array<B, 1> b{{B()}};

是因为这个特定版本的 gcc 没有完全实现 C++11 还是我遗漏了什么,第一个例子不正确?

Is it because this particular version of gcc doesn't fully implement C++11

很可能是的。 GCC 4.6 已经过时了。

or am I missing something and the first example is not correct?

关于 c++11 语法,您的示例很好。它在 colliru 编译,没有错误或警告。