This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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

--- Comment #9 from Andrew Savchenko <bircoph at gmail dot com> 2012-03-08 20:44:24 UTC ---
(In reply to comment #8)
> Looking at the preprocessed source I see that the member function template
> TStreamerInfo::ReadBuffer is declared in TStreamerInfo.h but only defined in
> the .cxx file.  If that function (which is public) is called from a different
> .cxx file then it will be implicitly instantiated, which isn't possible if the
> definition isn't visible.  The member function template definition should be
> moved to the header or there should be an explicit instantiation declaration
> (i.e. 'extern template' declaration) in the header and an explicit
> instantiation definition in the .cxx file.

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.

If all templates must be defined in the single header, this would make an
thousands lines of code header file. And explicit template will require
compile-tyme type specification, which is impossible due to RTTI being used.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]