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]

link failure with inline static member fn + virtual member


Hi,
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
{
public:
  static inline void Missing();
  virtual void  VF() const;
};
inline void A::Missing() { }

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

int main() 
{
  A::Missing();
  B::NotMissing();
  return 0;
}
--end inlinestatic.ii

--begin session log
nathan@laie:388>uname
-a                                                  
SunOS laie 5.5.1 Generic sun4u sparc SUNW,Ultra-1

nathan@laie:389>egcs-0803-g++ -v -g -c -o inlinestatic.o
inlinestatic.ii     
Reading specs from
/home/staff/nathan/solaris/local/SunOS_5/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.91.53/specs
gcc version egcs-2.91.53 19980803 (gcc2 ss-980609 experimental)

/home/staff/nathan/solaris/local/SunOS_5/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.91.53/cc1plus
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)    
/home/staff/nathan/solaris/egcs/bugs/inlinestatic.ii:19
00000000 T B::NotMissing(void) 
/home/staff/nathan/solaris/egcs/bugs/inlinestatic.ii:15

nathan@laie:391>egcs-0803-g++ -v -o inlinestatic
inlinestatic.o             
Reading specs from
/home/staff/nathan/solaris/local/SunOS_5/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.91.53/specs
gcc version egcs-2.91.53 19980803 (gcc2 ss-980609 experimental)

/home/staff/nathan/solaris/local/SunOS_5/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.91.53/collect2
-V -Y P,/usr/ccs/lib:/usr/lib -Qy -o inlinestatic
/home/staff/nathan/solaris/local/SunOS_5/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.91.53/crt1.o
/home/staff/nathan/solaris/local/SunOS_5/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.91.53/crti.o
/usr/ccs/lib/values-Xa.o
/home/staff/nathan/solaris/local/SunOS_5/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.91.53/crtbegin.o
-L/home/staff/nathan/solaris/local/SunOS_5/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.91.53
-L/home/staff/nathan/solaris/local/SunOS_5/sparc-sun-solaris2.5.1/lib
-L/usr/ccs/bin -L/usr/ccs/lib
-L/home/staff/nathan/solaris/local/SunOS_5/lib inlinestatic.o -lstdc++
-lm -lgcc -lc -lgcc
/home/staff/nathan/solaris/local/SunOS_5/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.91.53/crtend.o
/home/staff/nathan/solaris/local/SunOS_5/lib/gcc-lib/sparc-sun-solaris2.5.1/egcs-2.91.53/crtn.o
ld: Software Generation Utilities (SGU) SunOS/ELF (LK-2.0 (S/I) -
versioning)
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.

nathan
-- 
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
      You can up the bandwidth, but you can't up the speed of light      
nathan@acm.org  http://www.cs.bris.ac.uk/~nathan/  nathan@cs.bris.ac.uk


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