This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/33878] Pure virtual method body omitted from template
- From: "bangerth at math dot tamu dot edu" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 2 Apr 2008 18:34:57 -0000
- Subject: [Bug c++/33878] Pure virtual method body omitted from template
- References: <bug-33878-15256@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #18 from bangerth at math dot tamu dot edu 2008-04-02 18:34 -------
Subject: Re: Pure virtual method body omitted from template
> You are absolutely right as long as there is no multithreading and no
> dangling pointer. Sure. The thing is: If it's called, something bad has
> occured
I see your point, but in a case like this you are working outside what the
standard says (it would call the program erroneous and its
actions 'undefined'). The compiler's job being to translate what the standard
describes, you can't rely on any such behavior.
> * For templates the method is not generated, and we've discussed why. It's
> due to the template function emission rules: Not called, not emitted. But
> there is also the shortcut rule when deriving: Cannot be called, not
> emitted. That is what you explained. Thus here you have no choice.
You can instantiate explicitly if you want this.
By the way, there is also a rule somewhere in the standard that says that only
those templates must be instantiated that are actually needed; in other
words, the compiler cannot instantiate more functions just because someone
may want it to be there -- the functions must actually be *needed* for the
program to work correctly.
W.
-------------------------------------------------------------------------
Wolfgang Bangerth email: bangerth@math.tamu.edu
www: http://www.math.tamu.edu/~bangerth/
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33878