xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/template-linkage.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc // CHECK: Outer5Inner{{.*}}localE6memberE = external global
4*f4a2713aSLionel Sambuc 
5*f4a2713aSLionel Sambuc template<typename T> struct A {
fA6*f4a2713aSLionel Sambuc   virtual void f(T) { }
gA7*f4a2713aSLionel Sambuc   inline void g() { }
8*f4a2713aSLionel Sambuc };
9*f4a2713aSLionel Sambuc 
10*f4a2713aSLionel Sambuc // Explicit instantiations have external linkage.
11*f4a2713aSLionel Sambuc 
12*f4a2713aSLionel Sambuc // CHECK-LABEL: define weak_odr void @_ZN1AIiE1gEv(
13*f4a2713aSLionel Sambuc template void A<int>::g();
14*f4a2713aSLionel Sambuc 
15*f4a2713aSLionel Sambuc // CHECK-LABEL: define weak_odr void @_ZN1AIfE1fEf(
16*f4a2713aSLionel Sambuc // CHECK-LABEL: define weak_odr void @_ZN1AIfE1gEv(
17*f4a2713aSLionel Sambuc // FIXME: This should also emit the vtable.
18*f4a2713aSLionel Sambuc template struct A<float>;
19*f4a2713aSLionel Sambuc 
20*f4a2713aSLionel Sambuc // CHECK-LABEL: define weak_odr void @_Z1fIiEvT_
f(T)21*f4a2713aSLionel Sambuc template <typename T> void f(T) { }
22*f4a2713aSLionel Sambuc template void f<int>(int);
23*f4a2713aSLionel Sambuc 
24*f4a2713aSLionel Sambuc // CHECK-LABEL: define weak_odr void @_Z1gIiEvT_
g(T)25*f4a2713aSLionel Sambuc template <typename T> inline void g(T) { }
26*f4a2713aSLionel Sambuc template void g<int>(int);
27*f4a2713aSLionel Sambuc 
28*f4a2713aSLionel Sambuc template<typename T>
29*f4a2713aSLionel Sambuc struct X0 {
~X0X030*f4a2713aSLionel Sambuc   virtual ~X0() { }
31*f4a2713aSLionel Sambuc };
32*f4a2713aSLionel Sambuc 
33*f4a2713aSLionel Sambuc template<typename T>
34*f4a2713aSLionel Sambuc struct X1 : X0<T> {
35*f4a2713aSLionel Sambuc   virtual void blarg();
36*f4a2713aSLionel Sambuc };
37*f4a2713aSLionel Sambuc 
blarg()38*f4a2713aSLionel Sambuc template<typename T> void X1<T>::blarg() { }
39*f4a2713aSLionel Sambuc 
40*f4a2713aSLionel Sambuc extern template struct X0<char>;
41*f4a2713aSLionel Sambuc extern template struct X1<char>;
42*f4a2713aSLionel Sambuc 
43*f4a2713aSLionel Sambuc // CHECK-LABEL: define linkonce_odr void @_ZN2X1IcED1Ev(%struct.X1* %this) unnamed_addr
test_X1()44*f4a2713aSLionel Sambuc void test_X1() {
45*f4a2713aSLionel Sambuc   X1<char> i1c;
46*f4a2713aSLionel Sambuc }
47*f4a2713aSLionel Sambuc 
48*f4a2713aSLionel Sambuc namespace PR14825 {
49*f4a2713aSLionel Sambuc struct Outer {
50*f4a2713aSLionel Sambuc   template <typename T> struct Inner {
51*f4a2713aSLionel Sambuc     static int member;
52*f4a2713aSLionel Sambuc   };
GetPR14825::Outer53*f4a2713aSLionel Sambuc   template <typename T> void Get() {
54*f4a2713aSLionel Sambuc     int m = Inner<T>::member;
55*f4a2713aSLionel Sambuc   }
56*f4a2713aSLionel Sambuc };
57*f4a2713aSLionel Sambuc 
test()58*f4a2713aSLionel Sambuc void test() {
59*f4a2713aSLionel Sambuc   struct local {};
60*f4a2713aSLionel Sambuc   Outer o;
61*f4a2713aSLionel Sambuc   typedef void (Outer::*mptr)();
62*f4a2713aSLionel Sambuc   mptr method = &Outer::Get<local>;
63*f4a2713aSLionel Sambuc }
64*f4a2713aSLionel Sambuc }
65