From -4498538768688562358
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,8366734ec6aad121
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 1994-06-18 15:30:13 PST
Newsgroups: comp.std.c++
Path: nntp.gmd.de!Germany.EU.net!EU.net!howland.reston.ans.net!europa.eng.gtefsd.com!MathWorks.Com!solaris.cc.vt.edu!uunet!majipoor.cygnus.com!news!jason
From: jason@cygnus.com (Jason Merrill)
Subject: Re: new foo[0]
In-Reply-To: fjh@munta.cs.mu.OZ.AU's message of Sat, 18 Jun 1994 19:06:33 GMT
Content-Type: text/plain; charset=US-ASCII
Message-ID: <JASON.94Jun18150834@deneb.cygnus.com>
Sender: news@cygnus.com
Nntp-Posting-Host: deneb.cygnus.com
Organization: Cygnus Support, Mountain View, CA
References: <CquD6C.LEK@lehman.com> <9415818.9649@mulga.cs.mu.OZ.AU>
	<rfgCrKx5r.LMp@netcom.com> <9417005.12163@mulga.cs.mu.OZ.AU>
Mime-Version: 1.0
Date: Sat, 18 Jun 1994 22:08:33 GMT
Lines: 27

>>>>> Fergus Henderson <fjh@munta.cs.mu.OZ.AU> writes:

> Ah - now that you mention it - no, not in all contexts.
> I do think that it's use as the operand of `unary &' should be allowed.
> I don't know what the ARM or the latest working paper has to say
> about that.  (But most likely this is one of the areas where the
> working paper is "incorect, incomplet, and inConSisTeNT".)

I think that this falls into the provisions of [expr.add], since this
expression is equivalent to &(*(myfoo0+0)).  This section says basically
that evaluating a pointer arithmetic expression which points one past the
end of an array is allowed, but using that expression as the operand of the
unary * operator yields undefined behavior.  A strict reading would
indicate that the behavior of &myfoo[0] is thus undefined, but I suspect
that [expr.add] only meant to deal with actual dereferences.

> [On a related note, I don't think it should be allowed as the
> initializer for a reference, as in for example

> 	foo& r = myfoo0[0];

Certainly such usage would yield undefined behavior, if 'r' were ever
actually used for anything, and consequently an implementation can give a
diagnostic for such code.  I think that explicitly prohibiting this
particular initialization would, however, be excessive special-casing.

Jason


