[Bug target/14826] [AIX] Static Template members having different values in different instantiations of a template with the same arguments

gcc at pmade dot org gcc-bugzilla@gcc.gnu.org
Fri Apr 16 13:45:00 GMT 2004


------- Additional Comments From gcc at pmade dot org  2004-04-16 13:05 -------
I have written a smaller test case that might be useful for tracking down
this problem. I have included the code below as well. I can confirm this
problem on AIX 5.2 with GCC 3.3.3 and 3.3.2.

This, IMO, is a major show stopper. Many common idioms use template static
members, including the Singleton.

I am willing to take a stab at this, if someone points me in the right
direction. I suspect, along with others, that this is a weak symbol problem.



// file a.h
#ifndef _a_h_
#define _a_h_

template <typename T> class Static {
public:
    static void* get_addr (void)
    { return &t_; }

private:
    static T *t_;
};

template <typename T> T* Static<T>::t_ = 0;

void print_from_b (void);
void print_from_c (void);

#endif


// file b.cxx
#include "a.h"
#include <iostream>

void print_from_b (void)
{
    std::cout << "From B: " << Static<int>::get_addr() << "\n";
}


// file c.cxx
#include "a.h"
#include <iostream>

void print_from_c (void)
{
    std::cout << "From C: " << Static<int>::get_addr() << "\n";
}


// file main.cxx
#include "a.h"

int main (void)
{
    Static<int> s;

    print_from_b();
    print_from_c();

    return 0;
}


On FreeBSD:
>From B: 0x8089010
>From C: 0x8089010


On AIX 5.2:
>From B: 0x200179a0
>From C: 0x20017ac8


-- 


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



More information about the Gcc-bugs mailing list