Why does debugging "pure virtual method called" have to be so hard?

Mark Mitchell mark@markmitchell.com
Tue Oct 27 14:55:00 GMT 1998


>>>>> "Joe" == Joe Buck <jbuck@synopsys.com> writes:

    >> ... calling a pure virtual function has undefined behavior ...
    Joe> which means we can do what we want.

    Joe> I vote for throw __pure_virtual_exception;

    Joe> where that class is derived from class std::exception.

I can think of one reason not to do this, which may or may not be
persuasive to anyone.  Given:

  class C {
    virtual void f () throw () = 0;
  };

  C& c = g();
  c.f();

we would normally be able to optimize the call to `c.f()' by noting
that no exception could escape the call, and thereby avoid adding
handlers for that call, as well as avoiding abnormal critical edges in
the flow graphs.  Your proposal would make such an optimization
invalid, since such a call might still throw an exception.  (I don't
think GCC currently does the optimization I refer to here, but it
could, and should, and probably will in the future.)

I think calling terminate, abort, or some such is just fine.

-- 
Mark Mitchell 			mark@markmitchell.com
Mark Mitchell Consulting	http://www.markmitchell.com



More information about the Gcc mailing list