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]
Other format: [Raw text]

[Bug c++/21060] New: Symbol for static member of template is not emitted.


For a static member of a template class, the symbol doesn't appear to be emitted.
For example, with the code:
/*BEGIN CODE*/
#include <stdio.h>

template <class T>
class Base {
  public:
    static int bob;
    T a;
    Base() { printf("Base::Base starting\n"); fflush(stdout); }
    ~Base() { printf("Base::~Base::bob = %d\n", Base::bob); fflush(stdout); }
};

template <class T>
int Base<T>::bob = 10;


int main() {
    Base<float> b;
    fflush(stdout);
    return 0;
}
/*END CODE*/

if you attempt to compile directly to an executable, you get the following error:
/usr/bin/ld: Undefined symbols:
Base<float>::bob
collect2: ld returned 1 exit status


If you compile to object code (with -c option) and then use nm to dump the
symbols, you get:
m0135:/tmp olsonse$ nm -a bobby.o
         U __Unwind_Resume
         U __ZN4BaseIfE3bobE
00000088 t __ZN4BaseIfEC1Ev
000000d8 t __ZN4BaseIfED1Ev
         U ___gxx_personality_v0
         U ___sF
         U _fflush
00000000 T _main
         U _printf
         U dyld_stub_binding_helper

Note that the Base::bob is indicated to be Undefined.  If I use an earlier
compile on the same system (3.3.x), Base::bob is definitely shown as being present.

-- 
           Summary: Symbol for static member of template is not emitted.
           Product: gcc
           Version: 3.3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: olsonse at umich dot edu
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: powerpc-apple-darwin7.8.0
  GCC host triplet: powerpc-apple-darwin7.8.0
GCC target triplet: powerpc-apple-darwin7.8.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21060


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