g++ regression - or not ?

Artem Khodush artem@duma.gov.ru
Mon Jun 4 00:42:00 GMT 2001


> 
> consider this code: 
> 
> class Bar
> {
> public:
>     static void blah() { printf( "static method blah called\n" ); }
> };
> 
> class Foo
> {
> public:
>     static Bar *bar() { printf( "Foo::bar() called!\n" ); return new Bar; }
> };
> 
> int main()
> {
>     Foo::bar()->blah();
> }
> 
> price question: do you think Foo::bar() will be called, or not ?

This appears to be not a regression, since according to the standard, 
Foo::bar() indeed should be called: 

5.2.5 - Class member access [expr.ref]

-1- A postfix expression followed by a dot . or an arrow ->, optionally followed by 
the keyword template (temp.arg.explicit), and then followed by an id-expression, 
is a postfix expression. The postfix expression before the dot or arrow is evaluated;

[Footnote: This evaluation happens even if the result is unnecessary to determine 
the value of the entire postfix expression, for example if the id-expression denotes 
a static member. --- end foonote]

the result of that evaluation, together with the id-expression, determine the result 
of the entire postfix expression. 





More information about the Gcc-bugs mailing list