This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: C++ PATCH: Bug in ?: operator


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]