From 4121531487885487917
X-Google-Thread: f78e5,60dc9044ee8e77d3
X-Google-Attributes: gidf78e5,public
X-Google-Language: ENGLISH,ASCII
Path: g2news1.google.com!news1.google.com!newsread.com!news-xfer.newsread.com!news.alt.net!comp-std-cpp-robomod!not-for-mail
From: kanze@gabi-soft.fr
Newsgroups: comp.std.c++
Subject: Re: Strange new/new() problem
Date: Tue, 25 Jan 2005 12:00:43 CST
Organization: http://groups.google.com
Lines: 63
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <1106666062.736170.147510@f14g2000cwb.googlegroups.com>
References: <41ec486b$1@solnews.wv.mentorg.com>
   <1106064562.182462.247340@c13g2000cwb.googlegroups.com>
   <tG6Id.2117$V17.55312@twister1.libero.it>
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 8bit
Return-Path: <devnull@stump.algebra.com>
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
Delivered-To: std-c++@ucar.edu
X-Trace: posting.google.com 1106666067 14701 127.0.0.1 (25 Jan 2005 15:14:27 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Tue, 25 Jan 2005 15:14:27 +0000 (UTC)
User-Agent: G2/0.2
Complaints-To: groups-abuse@google.com
Injection-Info: f14g2000cwb.googlegroups.com; posting-host=62.160.54.162;
   posting-account=qsfl8gwAAABZGaLp2a7FeTfDkJamzWYW
X-Virus-Scanned: by amavisd-new at cs.mu.OZ.AU
X-MIME-Autoconverted: from quoted-printable to 8bit by mulga.cs.mu.OZ.AU id j0PFF8xM017160
X-Virus-Scanned: by amavisd-new at cs.mu.OZ.AU
Xref: g2news1.google.com comp.std.c++:3958

Alberto Barbati wrote:
> kanze@gabi-soft.fr wrote:
> > "Fedor G. Pikus" wrote:

> >>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".

> > The latter is only a warning, I hope.

> > <snip>

> > One could argue for a special rule barring the immediate
> > application of [] to the results of a new expression -- I
> > can't think of a case off hand where it is useful.
> > Orthogonality would argue against such a hack, of course,
> > but that shouldn't be the only consideration.

> According to the interpretation I gave in my other post, the
> compiler should indeed give an error, not a warning.  There's
> no need for a special rule to bar the application of [] to the
> result of new, because it seems to me that the current rules
> already make such application ill-formed. That's because []
> operates on a postfix-expression and "new (data*)" is not a
> postfix-expression.

That's a good point.  I simply applied the maximum munch rule to
the new expression, to determine its end, and then looked at
what was left.  Since the new expression can't be broken up, the
only issue of precedence is with the = operator, and obviously,
[] has precedence.  But as you point out, the standard doesn't
define expressions in terms of precedence, but by means of
productions.  You're right, and there is no production which can
produce the expression new (data*)[5].

Which means that the expression is illegal, and a compiler is
required to emit a diagnostic.

And that Comeau is wrong if it allows assigning the results to a
data*:-).

(Something like (new (data*))[5] is obviously legal, but IMHO,
that's really a case of "you asked for it, you got it".  I can't
quite see it occuring because of an incorrect understanding on
the part of the programmer.)

> Is there's something I'm missing?

I don't think so.  I think I was missing something.

--
James Kanze           GABI Software         http://www.gabi-soft.fr
Conseils en informatique orient�e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S�mard, 78210 St.-Cyr-l'�cole, France, +33 (0)1 30 23 00 34


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



