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
[alane@wwweasel alane]$ rpm -q gcc
[alane@wwweasel alane]$ rpm -q gcc-c++
[alane@wwweasel alane]$ g++ -O2 -c alzheimer.cpp
[alane@wwweasel alane]$ nm alzheimer.o
00000000 ? __FRAME_BEGIN__
00000000 t gcc2_compiled.
00000000 T subbandsynthesis__9MpegtorawPfT1
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:
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.