From 7694245353417549626
X-Google-Thread: 7894ca11fe,8390690191732735
X-Google-Attributes: gid7894ca11fe,public,usenet
X-Google-NewGroupId: yes
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news1.google.com!news2.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Sun, 20 Dec 2009 22:10:34 -0600
Return-Path: <cppmods@ruralroute.cs.rpi.edu>
To: (Usenet)
From: Scott Meyers <NeverRead@aristeia.com>
Newsgroups: comp.std.c++
Subject: Re: Why is std::array an aggregate?
Organization: albasani.net
Sender: cppmods@cs.rpi.edu
Approved: james.dennett@gmail.com
Message-ID: <hgmhf2$vuc$1@news.albasani.net>
References: <hgf8r0$7ta$1@news.albasani.net>
	<2fba9f88-3e5e-472f-a2fa-b7b415f07f69@g26g2000yqe.googlegroups.com>
	<hgiv5f$cca$1@news.albasani.net>
	<c93ad741-55bf-4ff2-8893-29261e44097d@l13g2000yqb.googlegroups.com>
Content-Type: text/plain; charset=windows-1252; format=flowed
X-Original-Date: Sun, 20 Dec 2009 17:02:23 -0800
X-Submission-Address: std-c++@netlab.cs.rpi.edu
Date: Sun, 20 Dec 2009 22:02:45 CST
Lines: 64
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-P4S8S221qm/xAqV4W4p+llnc2cL7CoLqnf3VY/AUYXSmlFr3OvohaVLu8bPzcZXDdxnXyV7OpsBtoGA!oyZBusM8Z/2i36wNuzyH3m9V5S7RS8EV7oiidZiCqrWMItW/55Gm6ns3
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
Xref: g2news1.google.com comp.std.c++:1951

James Kanze wrote:
>
> That still means you have to write the size.  An exception isn't
> as good as a compiler error, and a compiler error isn't as good
> as not having to write the size to begin with.

Perhaps, but I don't see your point, because you have to manually
specify the size of a std::array if you initialize it with a brace
initializer list, regardless.

> What's special is that it can also be initialized statically:
>
>     std::array< int, 3 > a = { 1, 2, 3 };
>
> Regardless of where this definition appears, I'm guaranteed that
> it occurs before *any* user defined code, including code in
> constructors of other static objects.  In certain cases, that's
> a useful guarantee.

Is this really true?  What about the following at namespace scope?

 std::array<int, 3> a = { f(), g(), h() };
 std::array<int, 3> b = { 1, 2, 3 };

Here's what draft C++0x has to say in 3.6.2/2, which I believe is
where we need to look:

> Objects with static storage duration (3.7.1) or thread storage duration
> (3.7.2) shall be zero-initialized (8.5) before any other initialization
> takes place.
> Constant initialization is performed:
>
> - if each full-expression (including implicit conversions) that appears in
>  the initializer of a reference with static or thread storage duration is a
>  constant expression (5.19) and the reference is bound to an lvalue
>  designating an object with static storage duration or to a temporary (see
>  12.2)
>
> - if an object with static or thread storage duration is initialized such
>  that the initialization satisfies the requirements for the object being
>  declared with constexpr (7.1.5).
>
> Together, zero-initialization and constant initialization are called static
> initialization; all other initialization is dynamic initialization.

In the code I showed, b isn't a reference, so the first bullet doesn't
apply.  b isn't declared constexpr either, so it's not clear to me
that the second bullet applies, either, although the wording is rather
odd.  If "the object" were changed to "an object," I'd probably
conclude that b can be statically initialized.  With the current
wording, "the object" pretty clearly refers to the object being
initialized, so as things stand now, I don't think that b can be
statically initialized.  If not, a would be initialized before b, and
in that case, arbitrary user code would be executed before b were
defined.

Scott

--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]



