c++/10761: [3.4] wrong virtual function called
snyder@fnal.gov
snyder@fnal.gov
Tue May 13 00:34:00 GMT 2003
>Number: 10761
>Category: c++
>Synopsis: [3.4] wrong virtual function called
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Mon May 12 23:16:01 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: scott snyder
>Release: 3.4 20030512 (experimental)
>Organization:
<organization of PR author (multiple lines)>
>Environment:
System: Linux karma 2.4.19-emp_2419p5a829i #1 Tue Sep 3 17:42:17 EST 2002 i686 i686 i386 GNU/Linux
Architecture: i686
<machine, os, target, libraries (multiple lines)>
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc/configure --prefix=/usr/local/gcc --enable-threads=posix --enable-long-long --enable-languages=c,c++,f77 : (reconfigured)
>Description:
Another case where we call the derived-class version of a virtual function,
in the face of an explicit request to call the version in the
base class.
The example below goes into an infinite recursive loop:
$ g++ -o x x.cc
$ ./x
B::foo
B::foo
B::foo
B::foo
B::foo
...
>How-To-Repeat:
---------------------------------------------
extern "C" int printf(...);
class A
{
public:
virtual ~A () {}
virtual void foo () { printf ("A::foo\n"); }
};
template <class T>
class B
: public A
{
public:
virtual void foo () {
printf ("B::foo\n");
this->A::foo ();
}
};
int main ()
{
B<int> b;
b.foo();
return 0;
}
---------------------------------------------
>Fix:
<how to correct or work around the problem, if known (multiple lines)>
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-bugs
mailing list