new expression as left operand of ->
Is the following program legal C++:
struct B
{
B* f() { return this ; }
} ;
int
main()
{
B* p = new B()->f() ; // line 10
return 0 ;
}
I'm particularly interested in line 10. Most compilers (but not
g++) seem to accept it, and it seems reasonable to accept it,
but formally, the standard says that the left operand of -> must
be a postfix-expression, and of course, a new-expression is not
a postfix-expression. So is it intentional that this is
illegal, and most compilers get it wrong, or is it an accidental
side effect of the way the standard is formulated, and most
compilers implement the actual intent. (The point, of course,
is that a new-expression is delimited by the keyword new on the
left, and by the limitations on the structure of a new-type-id
and the new-initializer on the right, so the above really
creates no ambiguity nor parsing problem.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
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.comeaucomputing.com/csc/faq.html ]