Description of Problem: See attached source. When compiling with -O2, a large virtual member function of a derived class that is defined as inlined in .cpp source, not header file, is not compiled, and an unresolved external reference is made instead. Since the function is defined in the .cpp file (and is only called from within that same file), it won't get compiled elsewhere either. The end result is that the function is undefined and the program using the class cannot link. How Reproducible: [alane@wwweasel alane]$ rpm -q gcc gcc-2.96-81 [alane@wwweasel alane]$ rpm -q gcc-c++ gcc-c++-2.96-81 [alane@wwweasel alane]$ g++ -O2 -c alzheimer.cpp [alane@wwweasel alane]$ nm alzheimer.o U Oops_I_forgot_to_compile_this__9Mpegtoraw 00000000 ? __FRAME_BEGIN__ 00000000 t gcc2_compiled. 00000000 T subbandsynthesis__9MpegtorawPfT1 [alane@wwweasel alane]$ Additional Information: Removing the virtual function from either the parent class or the derived class (or making the function non-virtual) eliminates the error. Compiling without -O2 also produces the correct result. This code is from a package called avifile. I have stripped it down to the smallest bit that would still exhibit the problem. Although I have not tested it, it would seem likely that this problem does not present on gcc-2.95, as I believe that is what the package author is using.
Created attachment 17828 [details] C++ source code to demonstrate gcc omitting compilation of large function
See my analysis: http://prak.org/pipermail/avifile/2001-May/001693.html http://prak.org/pipermail/avifile/2001-May/001700.html The issue is present in g++ 2.95.x as well, just in this case it throttles inlining a little bit later. If you make the routine larger (I think twice is enough, 4 times larger definitely is), it will fail the same way. Avifile authors apparently don't care unfortunately, so I'll probably include the patch I'm not too happy about.
I've included the patch in gcc-c++-2.96-85.