2014-01-15 03:35:09 +08:00
|
|
|
// RUN: %clang_cc1 -verify -Wno-return-type -Wno-main -std=c++11 -emit-llvm -triple %itanium_abi_triple -o - %s | FileCheck %s
|
2013-12-14 12:49:06 +08:00
|
|
|
// expected-no-diagnostics
|
|
|
|
|
2009-11-21 17:17:15 +08:00
|
|
|
namespace test1 {
|
|
|
|
int x;
|
|
|
|
template <int& D> class T { };
|
2015-02-18 15:47:09 +08:00
|
|
|
// CHECK: void @_ZN5test12f0ENS_1TIL_ZNS_1xEEEE(
|
2009-11-21 17:17:15 +08:00
|
|
|
void f0(T<x> a0) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace test1 {
|
|
|
|
// CHECK: void @_ZN5test12f0Ef
|
|
|
|
void f0(float) {}
|
|
|
|
template<void (&)(float)> struct t1 {};
|
2015-02-18 15:47:09 +08:00
|
|
|
// CHECK: void @_ZN5test12f1ENS_2t1IL_ZNS_2f0EfEEE(
|
2009-11-21 17:17:15 +08:00
|
|
|
void f1(t1<f0> a0) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace test2 {
|
|
|
|
// CHECK: void @_ZN5test22f0Ef
|
|
|
|
void f0(float) {}
|
|
|
|
template<void (*)(float)> struct t1 {};
|
2015-02-19 03:08:12 +08:00
|
|
|
// CHECK: void @_ZN5test22f1ENS_2t1IXadL_ZNS_2f0EfEEEE(
|
2009-11-21 17:17:15 +08:00
|
|
|
void f1(t1<f0> a0) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace test3 {
|
|
|
|
// CHECK: void @test3_f0
|
|
|
|
extern "C" void test3_f0(float) {}
|
|
|
|
template<void (&)(float)> struct t1 {};
|
2015-02-19 03:08:11 +08:00
|
|
|
// CHECK: void @_ZN5test32f1ENS_2t1IL_Z8test3_f0EEE(
|
2009-11-21 17:17:15 +08:00
|
|
|
void f1(t1<test3_f0> a0) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace test4 {
|
|
|
|
// CHECK: void @test4_f0
|
|
|
|
extern "C" void test4_f0(float) {}
|
|
|
|
template<void (*)(float)> struct t1 {};
|
2015-02-19 03:08:11 +08:00
|
|
|
// CHECK: void @_ZN5test42f1ENS_2t1IXadL_Z8test4_f0EEEE(
|
2009-11-21 17:17:15 +08:00
|
|
|
void f1(t1<test4_f0> a0) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK: void @test5_f0
|
|
|
|
extern "C" void test5_f0(float) {}
|
|
|
|
int main(int) {}
|
|
|
|
|
|
|
|
namespace test5 {
|
|
|
|
template<void (&)(float)> struct t1 {};
|
2015-02-18 15:47:09 +08:00
|
|
|
// CHECK: void @_ZN5test52f1ENS_2t1IL_Z8test5_f0EEE(
|
2009-11-21 17:17:15 +08:00
|
|
|
void f1(t1<test5_f0> a0) {}
|
|
|
|
|
|
|
|
template<int (&)(int)> struct t2 {};
|
2015-02-18 15:47:09 +08:00
|
|
|
// CHECK: void @_ZN5test52f2ENS_2t2IL_Z4mainEEE
|
2009-11-21 17:17:15 +08:00
|
|
|
void f2(t2<main> a0) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace test6 {
|
|
|
|
struct A { void im0(float); };
|
|
|
|
// CHECK: void @_ZN5test61A3im0Ef
|
|
|
|
void A::im0(float) {}
|
|
|
|
template <void(A::*)(float)> class T { };
|
2015-02-19 03:08:12 +08:00
|
|
|
// CHECK: void @_ZN5test62f0ENS_1TIXadL_ZNS_1A3im0EfEEEE(
|
2009-11-21 17:17:15 +08:00
|
|
|
void f0(T<&A::im0> a0) {}
|
|
|
|
}
|
2010-03-01 05:40:32 +08:00
|
|
|
|
|
|
|
namespace test7 {
|
|
|
|
template<typename T>
|
|
|
|
struct meta {
|
|
|
|
static const unsigned value = sizeof(T);
|
|
|
|
};
|
|
|
|
|
|
|
|
template<unsigned> struct int_c {
|
|
|
|
typedef float type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct X {
|
|
|
|
template<typename U>
|
|
|
|
X(U*, typename int_c<(meta<T>::value + meta<U>::value)>::type *) { }
|
|
|
|
};
|
|
|
|
|
2013-07-01 04:40:16 +08:00
|
|
|
// CHECK: define weak_odr {{.*}} @_ZN5test71XIiEC1IdEEPT_PNS_5int_cIXplL_ZNS_4metaIiE5valueEEsr4metaIS3_EE5valueEE4typeE(
|
2010-03-01 05:40:32 +08:00
|
|
|
template X<int>::X(double*, float*);
|
|
|
|
}
|
2010-03-01 06:05:49 +08:00
|
|
|
|
|
|
|
namespace test8 {
|
|
|
|
template<typename T>
|
|
|
|
struct meta {
|
|
|
|
struct type {
|
|
|
|
static const unsigned value = sizeof(T);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
template<unsigned> struct int_c {
|
|
|
|
typedef float type;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void f(int_c<meta<T>::type::value>) { }
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define weak_odr void @_ZN5test81fIiEEvNS_5int_cIXsr4metaIT_E4typeE5valueEEE(
|
2010-03-01 06:05:49 +08:00
|
|
|
template void f<int>(int_c<sizeof(int)>);
|
|
|
|
}
|
2010-04-23 11:10:43 +08:00
|
|
|
|
|
|
|
namespace test9 {
|
|
|
|
template<typename T>
|
|
|
|
struct supermeta {
|
|
|
|
template<typename U>
|
|
|
|
struct apply {
|
|
|
|
typedef T U::*type;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
struct X { };
|
|
|
|
|
|
|
|
template<typename T, typename U>
|
|
|
|
typename supermeta<T>::template apply<U>::type f();
|
|
|
|
|
|
|
|
void test_f() {
|
|
|
|
// CHECK: @_ZN5test91fIiNS_1XEEENS_9supermetaIT_E5applyIT0_E4typeEv()
|
|
|
|
// Note: GCC incorrectly mangles this as
|
|
|
|
// _ZN5test91fIiNS_1XEEENS_9supermetaIT_E5apply4typeEv, while EDG
|
|
|
|
// gets it right.
|
|
|
|
f<int, X>();
|
|
|
|
}
|
|
|
|
}
|
2010-04-28 13:58:56 +08:00
|
|
|
|
|
|
|
namespace test10 {
|
|
|
|
template<typename T>
|
|
|
|
struct X {
|
|
|
|
template<typename U>
|
|
|
|
struct definition {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// CHECK: _ZN6test101fIidEENS_1XIT_E10definitionIT0_EES2_S5_
|
|
|
|
template<typename T, typename U>
|
|
|
|
typename X<T>::template definition<U> f(T, U) { }
|
|
|
|
|
|
|
|
void g(int i, double d) {
|
|
|
|
f(i, d);
|
|
|
|
}
|
|
|
|
}
|
2012-01-06 13:06:35 +08:00
|
|
|
|
2014-06-06 06:11:20 +08:00
|
|
|
// Report from cxx-abi-dev, 2012.01.04.
|
2012-01-06 13:06:35 +08:00
|
|
|
namespace test11 {
|
|
|
|
int cmp(char a, char b);
|
|
|
|
template <typename T, int (*cmp)(T, T)> struct A {};
|
|
|
|
template <typename T> void f(A<T,cmp> &) {}
|
|
|
|
template void f<char>(A<char,cmp> &);
|
|
|
|
// CHECK: @_ZN6test111fIcEEvRNS_1AIT_L_ZNS_3cmpEccEEE(
|
|
|
|
}
|
2012-04-05 05:11:30 +08:00
|
|
|
|
|
|
|
namespace test12 {
|
|
|
|
// Make sure we can mangle non-type template args with internal linkage.
|
2013-12-14 12:49:06 +08:00
|
|
|
static int f() {}
|
2012-04-05 05:11:30 +08:00
|
|
|
const int n = 10;
|
|
|
|
template<typename T, T v> void test() {}
|
|
|
|
void use() {
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define internal void @_ZN6test124testIFivEXadL_ZNS_L1fEvEEEEvv(
|
2012-04-05 05:11:30 +08:00
|
|
|
test<int(), &f>();
|
2015-02-18 15:47:09 +08:00
|
|
|
// CHECK-LABEL: define internal void @_ZN6test124testIRFivEL_ZNS_L1fEvEEEvv(
|
2012-04-05 05:11:30 +08:00
|
|
|
test<int(&)(), f>();
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define internal void @_ZN6test124testIPKiXadL_ZNS_L1nEEEEEvv(
|
2012-04-05 05:11:30 +08:00
|
|
|
test<const int*, &n>();
|
2015-02-18 15:47:09 +08:00
|
|
|
// CHECK-LABEL: define internal void @_ZN6test124testIRKiL_ZNS_L1nEEEEvv(
|
2012-04-05 05:11:30 +08:00
|
|
|
test<const int&, n>();
|
|
|
|
}
|
|
|
|
}
|
2012-08-18 12:51:52 +08:00
|
|
|
|
|
|
|
// rdar://problem/12072531
|
|
|
|
// Test the boundary condition of minimal signed integers.
|
|
|
|
namespace test13 {
|
|
|
|
template <char c> char returnChar() { return c; }
|
|
|
|
template char returnChar<-128>();
|
|
|
|
// CHECK: @_ZN6test1310returnCharILcn128EEEcv()
|
|
|
|
|
|
|
|
template <short s> short returnShort() { return s; }
|
|
|
|
template short returnShort<-32768>();
|
|
|
|
// CHECK: @_ZN6test1311returnShortILsn32768EEEsv()
|
|
|
|
}
|
2013-12-04 17:01:55 +08:00
|
|
|
|
|
|
|
namespace test14 {
|
|
|
|
template <typename> inline int inl(bool b) {
|
|
|
|
if (b) {
|
|
|
|
static struct {
|
|
|
|
int field;
|
|
|
|
} a;
|
|
|
|
// CHECK: @_ZZN6test143inlIvEEibE1a
|
|
|
|
|
|
|
|
return a.field;
|
|
|
|
} else {
|
|
|
|
static struct {
|
|
|
|
int field;
|
|
|
|
} a;
|
|
|
|
// CHECK: @_ZZN6test143inlIvEEibE1a_0
|
|
|
|
|
|
|
|
return a.field;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int call(bool b) { return inl<void>(b); }
|
|
|
|
}
|