From -1578120885038685746
X-Google-Thread: f78e5,6bb94f62f97d8704,start
X-Google-NewGroupId: yes
X-Google-Attributes: gid7894ca11fe,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news1.google.com!news1.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: Fri, 16 Jul 2010 16:20:08 -0500
Return-Path: <cppmods@ruralroute.cs.rpi.edu>
To: (Usenet)
From: "Johannes Schaub (litb)" <schaub-johannes@web.de>
Newsgroups: comp.std.c++
Subject: A couple of questions on new-expression with array initializer
Followup-To: comp.std.c++
Organization: T-Online
Sender: cppmods@cs.rpi.edu
Approved: james.dennett@gmail.com
Message-ID: <i1nvr3$7r5$03$1@news.t-online.com>
Content-Type: text/plain; charset="ISO-8859-1"
X-Original-Date: Thu, 15 Jul 2010 23:52:11 +0200
X-Submission-Address: std-c++@netlab.cs.rpi.edu
Date: Fri, 16 Jul 2010 16:19:00 CST
Lines: 44
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-LrMmvK6lBTEC6hJPu7koObs4co75tyX5a8p7I3Dw0Imq8X4LTV6VdxrsKzdgUvEqaW8P+u/V9mglltW!OgHQG584/vMqMI4qGHiMHyoxy1Hu122yT/4yV/GqIu0ag2Ss4UrHvEyEa7qF
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++:2772

Q1:

The FCD says that the following code is ill-formed. But we can't know that
until runtime

int n = 2;
new int[n]{1, 2, 3};

How is the runtime supposed to emit the diagnostic message? See 8.5.1/6 and
5.3.4/15:

6 An initializer-list is ill-formed if the number of initializer-clauses
exceeds the number of members or elements to initialize.

Hmm, GCC just segfaults. I wonder whether printing "segfault" is a valid
runtime diagnostic message. Any insights?

Q2:

Is the following valid?

new (int[]){1, 2, 3}

I know that without the parens, it's syntactically invalid. But with the
parens, "int[]" it's a type-id and valid, but it says at 5.3.4/1:

"The new-expression attempts to create an object of the type-id (8.1) or
new-type-id to which it is applied. The type of that object is the allocated
type. This type shall be a complete object type, ..."

At first sight it seems to forbid it, because the type-id specifies an
incomplete type. But the constraint is done upon the object-type. And that
type is, after gone through 8.5.1, "int[3]". GCC forbids it and says "error:
invalid use of array with unspecified bounds". Is GCC right? Is there any
clear wording about it?

Thanks for any insight.

--
[ 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                      ]



