This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: C++ PATCH: Bug in ?: operator
- To: Mark Mitchell <mark at codesourcery dot com>
- Subject: Re: C++ PATCH: Bug in ?: operator
- From: Nathan Sidwell <nathan at acm dot org>
- Date: Thu, 02 Sep 1999 13:46:38 +0100
- CC: nathan at compsci dot bristol dot ac dot uk, jason at cygnus dot com, gcc-patches at gcc dot gnu dot org, Gabriel dot Dos-Reis at cmla dot ens-cachan dot fr
- References: <37C6C54C.EE7FBE9@acm.org> <19990827112730C.mitchell@codesourcery.com> <37CCEA25.D35BF468@acm.org> <19990901083035F.mitchell@codesourcery.com>
- Reply-To: nathan at compsci dot bristol dot ac dot uk
Not that it really matters, given we've decided on a course of action,
but...
Mark Mitchell wrote:
> We should imagine writing the undergraduate C++ interpreter, that does
> a simple recursive evaluation of expressions. When it sees `*vp' (in
> an rvalue context) it loads the memory pointed to. If you say `*&*vp'
> is loads it twice. Etc.
But `&' does not create an rvalue context. If you take '*vp' to mean an
access, whatever the context then we get some more weird effects.
[expr]5/4 talks about when a value can be `accessed', the above
interpretation of `*&*p' (not a volatile) would render the following
undefined
*&*p = 1;
If the inner * is an access of the pointed to scalar, then we've
violated
'the prior value shall be accessed only to determine the value to be
stored'
Of course in any sensible compiler the 'as-if' rule would delete the
inner access but pedantically we've already entered undefined territory.
Or maybe that expression is supposed to be undefined ... in which case,
x = *&*vp; //volatile this time
is supposed to read the volatile twice. But of course we're free to
combine these via [intro.execution]1.9/11 as there isn't a sequence
point between them (and that is what we do). So we do infact fold some
volatile accesses together under the above interpretation.
ho hum
nathan
--
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
I have seen the death of PhotoShop -- it is called GIMP
nathan@acm.org http://www.cs.bris.ac.uk/~nathan/ nathan@cs.bris.ac.uk