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++/16779] New: g++ template instantiation bug


I dont know for sure if this is a gcc bug. However, this code compiles and links fine with 
icc. 
 
 
// foo.h 
#ifndef FOO 
#define FOO 
 
#include <iostream> 
 
template <typename T> 
void foo() 
{ 
  std::cout << __PRETTY_FUNCTION__ << std::endl; 
} 
 
template <> 
void foo<int>() 
{ 
  std::cout << __PRETTY_FUNCTION__ << std::endl; 
} 
 
#endif 
 
 
// bar1.h 
#ifndef BAR1 
#define BAR1 
 
void bar1(); 
 
#endif 
 
 
// bar2.h 
#ifndef BAR2 
#define BAR2 
 
void bar2(); 
 
#endif 
 
 
// bar1.cpp 
#include "foo.h" 
#include "bar1.h" 
#include <iostream> 
 
void bar1() 
{ 
  std::cout << __PRETTY_FUNCTION__ << std::endl; 
} 
 
 
 
// bar2.cpp 
#include "foo.h" 
#include "bar2.h" 
#include <iostream> 
 
void bar2() 
{ 
  std::cout << __PRETTY_FUNCTION__ << std::endl; 
} 
 
 
 
// main.cpp 
#include "bar1.h" 
#include "bar2.h" 
 
int main(int argc, char* argv) 
{ 
  bar1(); 
  bar2(); 
} 
 
 
g++ bar1.cpp -c -o bar1.o 
g++ bar2.cpp -c -o bar2.o 
g++ main.cpp -c -o main.o 
g++ bar1.o bar2.o main.o -o main 
 
 
bar2.o(.text+0x0): In function `void foo<int>()': 
: multiple definition of `void foo<int>()' 
bar1.o(.text+0x0): first defined here 
collect2: ld returned 1 exit status 
 
 
gcc -v 
Reading specs from /usr/local/lib/gcc-lib/i686-pc-linux-gnu/3.3/specs 
Configured with: ./configure 
Thread model: posix 
gcc version 3.3 
 
ld -v 
GNU ld version 2.13.90.0.18 20030121 (SuSE Linux) 
 
 
when the foo<int> template specialization is removed, everything works fine.

-- 
           Summary: g++ template instantiation bug
           Product: gcc
           Version: 3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ares dot lagae at cs dot kuleuven dot ac dot be
                CC: gcc-bugs at gcc dot gnu dot org


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


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