[Bug c++/59246] GCC should issue runtime error for calling pure virtual function with definition
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Nov 22 11:26:00 GMT 2013
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59246
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2013-11-22
Ever confirmed|0 |1
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Ryou Ezoe from comment #0)
> // call by unqualified name is virtual function call.
> // virtual function call during destruction is undefined.
N.B. it's only undefined if the function is a pure virtual, not in general, and
you do get a warning:
pv.cc: In destructor ‘virtual Base::~Base()’:
pv.cc:14:7: warning: pure virtual ‘virtual void Base::f()’ called from
destructor [enabled by default]
f() ;
^
Here's a complete testcase (you can't get a runtime error if your program can't
be run!)
struct Base
{
virtual void f() = 0 ;
virtual ~Base() ;
} ;
// pure virtual function with definition
void Base::f() { }
Base::~Base()
{
// call by unqualified name is virtual function call.
// virtual function call during destruction is undefined.
f() ;
}
struct Derived : Base
{
void f() { }
};
int main()
{
Derived d;
}
More information about the Gcc-bugs
mailing list