g++ regression - or not ?
Dirk Mueller
dmuell@gmx.net
Sat Jun 2 15:20:00 GMT 2001
Hi,
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 ?
with gcc 2.x and quite a few other compilers it won't. with gcc 3 it is
called. I think this is a bit more consistent, still I consider it a
optimisation-regression. Am I wrong ?
I'm pretty surprised that there is no warning for the Foo::bar()->blah()
call. I'd expected one, because this is certainly very bad and misleading
coding style. Its not obvious that most compilers will optimize the
Foo::bar() call away. I'd even be okay with an error.
Opinions ? Comments from the C++ standard experts? :-)
Please keep me in CC, thanks.
Dirk
More information about the Gcc-bugs
mailing list