This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
g++ regression - or not ?
- To: gcc-bugs at gcc dot gnu dot org
- Subject: g++ regression - or not ?
- From: Dirk Mueller <dmuell at gmx dot net>
- Date: Sun, 3 Jun 2001 00:20:06 +0200
- Cc: dmuell at gmx dot net
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