Creating two files: ==== t1.cpp === #include <tr1/unordered_map> std::tr1::unordered_map<int,int> map1; int main() {} ==== t2.cpp ==== #include <tr1/unordered_map> std::tr1::unordered_map<int, float> map; int t2(int i) { return 0; } ============= compiling them with g++ -Wall t1.cpp t2.cpp leads to compiler output: t2.o:(.bss+0x20): multiple definition of `std::tr1::placeholders::(anonymous namespace)::_10' t1.o:(.bss+0x20): first defined here t2.o:(.bss+0x21): multiple definition of `std::tr1::placeholders::(anonymous namespace)::_9' t1.o:(.bss+0x21): first defined here t2.o:(.bss+0x22): multiple definition of `std::tr1::placeholders::(anonymous namespace)::_8' t1.o:(.bss+0x22): first defined here t2.o:(.bss+0x23): multiple definition of `std::tr1::placeholders::(anonymous namespace)::_7' t1.o:(.bss+0x23): first defined here t2.o:(.bss+0x24): multiple definition of `std::tr1::placeholders::(anonymous namespace)::_6' t1.o:(.bss+0x24): first defined here t2.o:(.bss+0x25): multiple definition of `std::tr1::placeholders::(anonymous namespace)::_5' t1.o:(.bss+0x25): first defined here t2.o:(.bss+0x26): multiple definition of `std::tr1::placeholders::(anonymous namespace)::_4' t1.o:(.bss+0x26): first defined here t2.o:(.bss+0x27): multiple definition of `std::tr1::placeholders::(anonymous namespace)::_3' t1.o:(.bss+0x27): first defined here t2.o:(.bss+0x28): multiple definition of `std::tr1::placeholders::(anonymous namespace)::_2' t1.o:(.bss+0x28): first defined here t2.o:(.bss+0x29): multiple definition of `std::tr1::placeholders::(anonymous namespace)::_1' t1.o:(.bss+0x29): first defined here t2.o:(.bss+0x2a): multiple definition of `std::tr1::(anonymous namespace)::ignore' t1.o:(.bss+0x2a): first defined here t2.o:(.data+0x0): multiple definition of `_ZN8Internal1XIXT_EE8n_primesE' t1.o:(.data+0x0): first defined here ========== Thus preventing use of two unordered_map's in a single application. g++ -v: Using built-in specs. Target: i486-linux-gnu Configured with: ../src/configure -v --enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --program-suffix=-4.0 --enable-__cxa_atexit --enable-libstdcxx-allocator=mt --enable-clocale=gnu --enable-libstdcxx-debug --enable-java-gc=boehm --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre --enable-mpfr --disable-werror --enable-checking=release i486-linux-gnu Thread model: posix gcc version 4.0.2 (Debian 4.0.2-2)
Hmm, there are two problems here, unless _ZN8Internal1XIXT_EE8n_primesE is what is really broken in libstdc++'s headers.
Hmm template<int dummy> struct X { static const int n_primes = 256; static const unsigned long primes[n_primes + 1]; }; template<int dummy> const int X<dummy>::n_primes; template<int dummy> const unsigned long X<dummy>::primes[n_primes + 1] = { 0 }; and then use X<0>::primes in a function.
Note that I cannot reproduce with 4.0.0 and 4.0.1. I'm wondering whether is even more fallout from that static patch :( ... CC-ing Mark
(In reply to comment #3) > Note that I cannot reproduce with 4.0.0 and 4.0.1. I'm wondering whether is > even > more fallout from that static patch :( ... CC-ing Mark It looks like it. file1.c: template<int dummy> struct X { static const int n_primes = 256; static const unsigned long primes[n_primes + 1]; }; template<int dummy> const int X<dummy>::n_primes; template<int dummy> const unsigned long X<dummy>::primes[n_primes + 1] = { 0 }; const unsigned long *f(void){return &X<0>::primes[0];} ------------------------------ file2.c: template<int dummy> struct X { static const int n_primes = 256; static const unsigned long primes[n_primes + 1]; }; template<int dummy> const int X<dummy>::n_primes; template<int dummy> const unsigned long X<dummy>::primes[n_primes + 1] = { 0 }; const unsigned long *f1(void){return &X<0>::primes[0];} int main(){} ------- Compile and link, this fails.
The problem is that the variable X<0>:: primes is not being marked as weak which causes the rest to fail also because we are using that name for the first non-weak global symbol to name anonymous namespace.
*** Bug 24390 has been marked as a duplicate of this bug. ***
Subject: Bug 24389 CVSROOT: /cvs/gcc Module name: gcc Changes by: mmitchel@gcc.gnu.org 2005-10-16 23:16:28 Modified files: gcc/cp : decl2.c init.c pt.c Added files: gcc/testsuite/g++.dg/template: static21.C static21-a.cc Log message: PR c++/24389 * decl2.c (mark_used): Use uses_template_parms instead of dependent_type_p. * init.c (constant_value_1): Handle uninstantiated templates specially. * pt.c (instantiate_decl): Add sanity check. PR c++/24389 * g++.dg/template/static21.C: New test. * g++.dg/template/static21-a.cc: Likewise. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/static21.C.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/static21-a.cc.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl2.c.diff?cvsroot=gcc&r1=1.803&r2=1.804 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/init.c.diff?cvsroot=gcc&r1=1.432&r2=1.433 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.1048&r2=1.1049
Subject: Bug 24389 CVSROOT: /cvs/gcc Module name: gcc Changes by: mmitchel@gcc.gnu.org 2005-10-16 23:17:53 Modified files: gcc/cp : ChangeLog gcc/testsuite : ChangeLog Log message: PR c++/24389 * decl2.c (mark_used): Use uses_template_parms instead of dependent_type_p. * init.c (constant_value_1): Handle uninstantiated templates specially. * pt.c (instantiate_decl): Add sanity check. PR c++/24389 * g++.dg/template/static21.C: New test. * g++.dg/template/static21-a.cc: Likewise. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4939&r2=1.4940 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.6200&r2=1.6201
Subject: Bug 24389 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-4_0-branch Changes by: mmitchel@gcc.gnu.org 2005-10-16 23:19:00 Modified files: gcc/cp : decl2.c init.c pt.c ChangeLog gcc/testsuite : ChangeLog Added files: gcc/testsuite/g++.dg/template: static21.C static21-a.cc Log message: PR c++/24389 * decl2.c (mark_used): Use uses_template_parms instead of dependent_type_p. * init.c (constant_value_1): Handle uninstantiated templates specially. * pt.c (instantiate_decl): Add sanity check. PR c++/24389 * g++.dg/template/static21.C: New test. * g++.dg/template/static21-a.cc: Likewise. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/static21.C.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/static21-a.cc.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl2.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.770.2.10&r2=1.770.2.11 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/init.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.412.2.11&r2=1.412.2.12 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.978.2.32&r2=1.978.2.33 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.4648.2.137&r2=1.4648.2.138 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5084.2.460&r2=1.5084.2.461
Fixed in 4.0.3.