Topic: cast-exp using reference is lvalue?
Author: James Powell <james@advancedsw.com>
Date: 1996/12/04 Raw View
Hi folks,
I'm attempting to parse C++ using the grammar given in the DWP of 4/28/95, and I've run
into an anomaly that I'm hoping you can help me understand.
The code looks like this:
class testB : testA {
testB& operator=(const testB& l) {
return (testB&) ((testA&)*this = (const testA&)l);
}
};
The strange thing is that "(testA&)*this" looks like a cast-expression, but the grammar
won't allow a cast-expression as the left-hand side of an assignment-expression. Yet,
the code does compile, at least using Sun's C++. I'm able to parse it by changing the
definition of assignment-expression from:
assignment-expression:
conditional-expression
unary-expression assignment-operator assignment-expression
throw-expression
to:
assignment-expression:
conditional-expression
unary-expression assignment-operator assignment-expression
cast-expression assignment-operator assignment-expression
throw-expression
This'll probably suffice for our purposes (reverse engineering), but of course it isn't
correct ("(int) x = 5;" is still a syntax error). I am curious about the reasoning
behind this special-case extension of the lvalue, and whether it's in the standard, and
how it might be defined more explicitly. Help? Thanks in advance,
-James-
------------------------------------------------------------------------------
James Powell james@advancedsw.com Go ahead, squeeze the wheeze
------------------------------------------------------------------------------
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: fjh@murlibobo.cs.mu.OZ.AU (Fergus Henderson)
Date: 1996/12/05 Raw View
James Powell <james@advancedsw.com> writes:
>I'm attempting to parse C++ using the grammar given in the DWP of 4/28/95
[...]
>assignment-expression:
> conditional-expression
> unary-expression assignment-operator assignment-expression
> throw-expression
In the November 96 draft, this is
assignment-expression:
conditional-expression
logical-or-expression assignment-operator assignment-expression
throw-expression
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]