[Bug c++/40056] implicit instantiation of function templates fails with -O2, works with -O and -g...

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Mar 8 21:06:00 GMT 2012


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40056

--- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-03-08 21:05:02 UTC ---
(In reply to comment #9)
> Hmm, I can't understand this (though I don't know all the details of the C++
> standard). If I'm writing class MyClass with public method Read, this is
> absolutely normal to declare Read function in the class declaration in the
> MyClass.h header and define it in the MyClass.cpp. Templates are supposed to
> work just as a normal functions, with the difference that code is written once,
> instead of writing a bunch of overloaded functions.

No, they aren't just like normal functions.

Maybe you should read
http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12

> If all templates must be defined in the single header, this would make an
> thousands lines of code header file.

Who said they have to be in a /single/ header?

Have you ever looked at the implementation of e.g. <string> or <vector>?
They're entirely defined in headers.  There's a reason for that.

> And explicit template will require
> compile-tyme type specification, which is impossible due to RTTI being used.

I don't know what RTTI has to do with anything and don't know what you mean.

The explicit instantiation you need is the one that you get a linker error for
i.e.
extern template
  int TStreamerInfo::ReadBuffer(TBuffer&, char** const&, int, int, int, int);



More information about the Gcc-bugs mailing list