This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/47940] warn about calls to a pure virtual from a constructor/destructor
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 1 Mar 2011 12:30:13 +0000
- Subject: [Bug c++/47940] warn about calls to a pure virtual from a constructor/destructor
- Auto-submitted: auto-generated
- References: <bug-47940-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47940
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-03-01 12:30:06 UTC ---
(In reply to comment #0)
>
> Functions that call pure virtual functions cannot
> be called from constructors and destructors.
> This may be discovered at compile-time, and the above
> text makes a good error/warning message.
I'm not sure it makes a good diagnostic, consider:
struct abc {
abc(bool nasal_demons) { if (nasal_demons) fly(); }
void fly() { doFly(); }
virtual void doFly() = 0;
};
Ideally the diagnostic for this would say "may call a pure virtual" for cases
where it can't be determined.
But then I don't really like the current diagnostic for direct calls either:
warning: abstract virtual 'virtual void abc::doFly()' called from constructor
I don't like the duplication of the word "virtual" and I don't like the term
"abstract virtual" - the class is abstract, the function is pure virtual.