[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 Andrew Savchenko changed: What|Removed |Added CC||bircoph at gmail dot com --- Comment #5 from Andrew Savchenko 2012-03-08 14:28:48 UTC --- The problem is still here with gcc-4.5.3 if compiled with -O3: x86_64-pc-linux-gnu-gcc -O -march=core2 -m64 -c TStreamerInfoReadBuffer.cxx -o TStreamerInfoReadBuffer-1.o x86_64-pc-linux-gnu-gcc -O2 -march=core2 -m64 -c TStreamerInfoReadBuffer.cxx -o TStreamerInfoReadBuffer-2.o x86_64-pc-linux-gnu-gcc -O3 -march=core2 -m64 -c TStreamerInfoReadBuffer.cxx -o TStreamerInfoReadBuffer-1.o nm TStreamerInfoReadBuffer-1.o | grep _ZN13TStreamerInfo10ReadBufferIPPcEEiR7TBufferRKT_ W _ZN13TStreamerInfo10ReadBufferIPPcEEiR7TBufferRKT_ nm TStreamerInfoReadBuffer-2.o | grep _ZN13TStreamerInfo10ReadBufferIPPcEEiR7TBufferRKT_ W _ZN13TStreamerInfo10ReadBufferIPPcEEiR7TBufferRKT_ nm TStreamerInfoReadBuffer-3.o | grep _ZN13TStreamerInfo10ReadBufferIPPcEEiR7TBufferRKT_ 7b10 t _ZN13TStreamerInfo10ReadBufferIPPcEEiR7TBufferRKT_.clone.26 The guilty is -fipa-cp-clone option. Without it symbol is defined well: x86_64-pc-linux-gnu-gcc -O3 -fno-ipa-cp-clone -march=core2 -m64 -c TStreamerInfoReadBuffer.cxx -o TStreamerInfoReadBuffer-3-fipa-cp-clone.o nm TStreamerInfoReadBuffer-3-fipa-cp-clone.o | grep _ZN13TStreamerInfo10ReadBufferIPPcEEiR7TBufferRKT_ W _ZN13TStreamerInfo10ReadBufferIPPcEEiR7TBufferRKT_
[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 #7 from Andrew Savchenko 2012-03-08 15:11:04 UTC --- Ok, thanks for clarification. The problem is that I'm not a developer of this program, I just maintain its package for Gentoo. To make things worse I can't reproduce the build failure myself on any of my hosts. But users continue to complain one after another, so this issue needs to be cleared out. However, I can tell that -fno-implicit-templates was never used during compilation and I can't find any extern template declarations in that code; though code is rather sophisticated, I may missed something tricky.
[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 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.
[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 #12 from Andrew Savchenko 2012-03-08 23:27:15 UTC --- Hello, (In reply to comment #10) > No, they aren't just like normal functions. > > Maybe you should read > http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12 Thank you again, I misunderstood concept behind template implementation. (In reply to comment #11) > the source code now (r43307) uses explicit instantiation and should work on > Gentoo with all compiler versions and optimization levels. > > If you want older versions to work remove the conditionals at the bottom of > io/io/Module.mk. Thanks for fixing this problem. I'll apply the solution to our packages soon.