Re: array + return + initializer (C++0X) - is this a bug
On 2011-04-08 14:06, Johannes Schaub wrote:
Daniel Kr??gler wrote:
This has the unfortunate consequences, that it does not say anything about
other feasible initialization forms, which influences especially the
zero-length array case. It is unclear whether
std::array<int, 0> b1{};
is well-formed or whether
std::array<int, 0> b2{{}};
can or must be used instead, which obviously depends on the actual
implementation. The latter form would be invalid, if the specialization
would be an empty class, the first form would be invalid, if the
specialization contains a single element of type T[1].
Why would it be invalid for a specialization that contains a single element
of type T[1] ? The syntax "{}" doesn't elide any brace. It just doesn't
initialize the array member, which means the array member is value
initialized.
You are right, I think I was simply misguided here, because there is a
way of looking at
std::array<int, 0> b1{}
as the elided form of
std::array<int, 0> b2{{}};
but I agree that this is clearly described in list-initialization and
non-ambigious from the overall text in the standard.
In fact, for list-initialization with empty initializer lists of classes
that have a default constructor, we don't enter aggregate initialization at
all: We will do value initialization of the std::array<> object regardless,
instead.
You are right, I was plain wrong in regard to this point.
I still think that the zero-length specialization of std::array should
be required to be DefaultConstructible independent from the element
type, because - at least conceptually - there is no real member existing.
Thanks & Greetings from Bremen,
- Daniel Kr??gler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]