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

101 views Asked by At

Consider the following example:

#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;
}

when trying to compile it with g++ 4.6.3 and -std=c++0x I get this error:

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>&&’

However, the same brace initialization works when defining a variable:

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

Is it because this particular version of gcc doesn't fully implement C++11 or am I missing something and the first example is not correct?

1

There are 1 answers

0
πάντα ῥεῖ On BEST ANSWER

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

Most probably yes. GCC 4.6 is pretty outdated.

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

Regarding c++11 syntax your example is fine. It compiles at colliru without errors or warnings.