This is the mail archive of the 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]

link failure with inline static member fn + virtual member

this is an utterly confusing bug involving a class with an inline static
member function and a declared, but not defined virtual member function.
The compiler does not emit a body for the inline member fn. If the
compiler is not perfoming inlining, it is left to the linker to resolve
calls to the function. The linker fails, because there is no definition
of the label present in the object file. The link fails naming the
inline static as missing.

Here is an example program, showing two classes, the only difference
being that in one the static member function is inline (A::Missing), and
it isn't in the other (B::NotMissing)
--begin inlinestatic.ii
class A
  static inline void Missing();
  virtual void  VF() const;
inline void A::Missing() { }

class B
  static void NotMissing();
  virtual void  VF() const;
void B::NotMissing() { }

int main() 
  return 0;
--end inlinestatic.ii

--begin session log
SunOS laie 5.5.1 Generic sun4u sparc SUNW,Ultra-1

nathan@laie:389>egcs-0803-g++ -v -g -c -o inlinestatic.o
Reading specs from
gcc version egcs-2.91.53 19980803 (gcc2 ss-980609 experimental)

inlinestatic.ii -quiet -g -version -o /var/tmp/ccZDunke.s
GNU C++ version egcs-2.91.53 19980803 (gcc2 ss-980609 experimental)
(sparc-sun-solaris2.5.1) compiled by GNU C version 2.8.1.
 /usr/ccs/bin/as -V -Qy -s -o inlinestatic.o /var/tmp/ccZDunke.s
/usr/ccs/bin/as: SC4.2 dev 30 Nov 1995

nathan@laie:390>nm -C -l inlinestatic.o | grep Missing           
         U A::Missing(void)    
00000000 T B::NotMissing(void) 

nathan@laie:391>egcs-0803-g++ -v -o inlinestatic
Reading specs from
gcc version egcs-2.91.53 19980803 (gcc2 ss-980609 experimental)

-V -Y P,/usr/ccs/lib:/usr/lib -Qy -o inlinestatic
-L/usr/ccs/bin -L/usr/ccs/lib
-L/home/staff/nathan/solaris/local/SunOS_5/lib inlinestatic.o -lstdc++
-lm -lgcc -lc -lgcc
ld: Software Generation Utilities (SGU) SunOS/ELF (LK-2.0 (S/I) -
Undefined                       first referenced
 symbol                             in file
A::Missing(void)                    inlinestatic.o
ld: fatal: Symbol referencing errors. No output written to inlinestatic
collect2: ld returned 1 exit status
--end session log

As you can see this is the 1998/08/03 snapshot. nm shows that
B::NotMissing is defined, and A::Missing is not defined.

Dr Nathan Sidwell :: Computer Science Department :: Bristol University
      You can up the bandwidth, but you can't up the speed of light

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