From 4060323868671306455
X-Google-Thread: f78e5,60dc9044ee8e77d3
X-Google-Attributes: gidf78e5,public
X-Google-Language: ENGLISH,ASCII-7-bit
Return-Path: <devnull@stump.algebra.com>
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
Path: g2news1.google.com!news2.google.com!newsfeed.stanford.edu!comp-std-cpp-robomod!not-for-mail
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
Delivered-To: std-c++@ucar.edu
From: "msalters" <Michiel.Salters@logicacmg.com>
Newsgroups: comp.std.c++
Subject: Re: Strange new/new() problem
Organization: http://groups.google.com
Message-ID: <1106038227.037429.135930@c13g2000cwb.googlegroups.com>
References: <41ec486b$1@solnews.wv.mentorg.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1106038232 32165 127.0.0.1 (18 Jan 2005 08:50:32 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Tue, 18 Jan 2005 08:50:32 +0000 (UTC)
User-Agent: G2/0.2
Complaints-To: groups-abuse@google.com
Injection-Info: c13g2000cwb.googlegroups.com; posting-host=212.123.206.71;
   posting-account=G8Vn6AwAAAAe3s4qFj7nFOuhEuzTNEir
X-Spamscanner: mailbox7.ucsd.edu  (v1.5 Dec  3 2004 17:34:44, -2.8/5.0 3.0.0)
X-MailScanner: PASSED (v1.2.8 94742 j0I8oWkY006113 mailbox7.ucsd.edu)
X-Virus-Scanned: by amavisd-new at cs.mu.OZ.AU
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
X-Virus-Scanned: by amavisd-new at cs.mu.OZ.AU
Date: Tue, 18 Jan 2005 10:34:35 CST
Xref: g2news1.google.com comp.std.c++:3904


"Fedor G. Pikus" wrote:
> Consider this example:
> struct data { /****/ };
> int main() {
>      data** p = new (data*)[5];
> }
>
> What the programmer wanted is to allocate an array of pointers, of
> course, and the parenthesis are unnecessary but arguably make reading

> the code easier.

In this case, yes. 5.3.4/3 shows precisely why parenthesis are
sometimes needed.

> GCC compiled the code just fine, and did what the programmer wanted,
but
> several other compilers refused. Error messages are of two types:
either
> it's "cannot assign data* to data**" or "[5] is unexpected". Comeau
> falls into the first cathegory, and I usually trust Comeau to get it
> right. Both messages suggest that these compilers interpret this code
as
> the placement new with "data *" being the location, even though it's
a
> type, not a variable.

There are two possible forms of a new-expression:
new new-placement_opt new-type-id new-initializer_opt
new new-placement_opt( typeid ) new-initializer_opt

Your form is /not/ the latter. [5] cannot be parsed as a
new-initializer. The next step is to look at the new-type-id
which has the form type-specifier_seq new-declarator_opt

type-specifier_seq is just a sequence of type-specifier's. There
are quite a number of possible type-specifier's, but none start
with a (. The optional new-placement part /does/ start with an
(, so the confusion of the compiler is fully understandable.
HTH,
Michiel Salters

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



