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++/25748] New: Template instantiated twice


In 3.4.4 under Cygwin (but not under 3.4.0 and Debian GNU/Linux) the following 
situation causes "duplicate definition" linker errors:

1) A template class has a static data member:
  template<typename T> struct foo { static T t; };
2) The static member is template-defined at file scope in one module:
  template<typename T> T foo<T>::t = 0;
3) And also defined in the anonymous namespace in another module:
   namespace {   template<typename T> T foo<T>::t = 0; }
4) The template itself is instantiated in the namespace in the same module:
   namespace { foo<int> f; }
5) and also at file scope in some other module:
    foo<int> g;

then the linker produces "multiple definition" messages for the static member.
I am not sure whether collect2 is instantiating the same template twice, or
whether it is instantiating each of the two templates once each but is not
qualifying the name of the anonymous version with the namespace name.


-- 
           Summary: Template instantiated twice
           Product: gcc
           Version: 3.4.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: igodard at pacbell dot net


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



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