| Daniel Dunbar | 8fbe78f | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s | 
| Daniel Dunbar | 88ad4c5 | 2009-11-21 09:17:15 +0000 | [diff] [blame] | 2 | namespace test1 { | 
|  | 3 | int x; | 
|  | 4 | template <int& D> class T { }; | 
|  | 5 | // CHECK: void @_ZN5test12f0ENS_1TILZNS_1xEEEE( | 
|  | 6 | void f0(T<x> a0) {} | 
|  | 7 | } | 
|  | 8 |  | 
|  | 9 | namespace test1 { | 
|  | 10 | // CHECK: void @_ZN5test12f0Ef | 
|  | 11 | void f0(float) {} | 
|  | 12 | template<void (&)(float)> struct t1 {}; | 
|  | 13 | // CHECK: void @_ZN5test12f1ENS_2t1ILZNS_2f0EfEEE( | 
|  | 14 | void f1(t1<f0> a0) {} | 
|  | 15 | } | 
|  | 16 |  | 
|  | 17 | namespace test2 { | 
|  | 18 | // CHECK: void @_ZN5test22f0Ef | 
|  | 19 | void f0(float) {} | 
|  | 20 | template<void (*)(float)> struct t1 {}; | 
|  | 21 | // FIXME: Fails because we don't treat as an expression. | 
|  | 22 | // CHECK-FIXME: void @_ZN5test22f1ENS_2t1IXadL_ZNS_2f0EfEEEE( | 
|  | 23 | void f1(t1<f0> a0) {} | 
|  | 24 | } | 
|  | 25 |  | 
|  | 26 | namespace test3 { | 
|  | 27 | // CHECK: void @test3_f0 | 
|  | 28 | extern "C" void test3_f0(float) {} | 
|  | 29 | template<void (&)(float)> struct t1 {}; | 
|  | 30 | // FIXME: Fails because we tack on a namespace. | 
|  | 31 | // CHECK-FIXME: void @_ZN5test32f1ENS_2t1ILZ8test3_f0EEE( | 
|  | 32 | void f1(t1<test3_f0> a0) {} | 
|  | 33 | } | 
|  | 34 |  | 
|  | 35 | namespace test4 { | 
|  | 36 | // CHECK: void @test4_f0 | 
|  | 37 | extern "C" void test4_f0(float) {} | 
|  | 38 | template<void (*)(float)> struct t1 {}; | 
|  | 39 | // FIXME: Fails because we don't treat as an expression. | 
|  | 40 | // CHECK-FIXME: void @_ZN5test42f1ENS_2t1IXadL_Z8test4_f0EEEE( | 
|  | 41 | void f1(t1<test4_f0> a0) {} | 
|  | 42 | } | 
|  | 43 |  | 
|  | 44 | // CHECK: void @test5_f0 | 
|  | 45 | extern "C" void test5_f0(float) {} | 
|  | 46 | int main(int) {} | 
|  | 47 |  | 
|  | 48 | namespace test5 { | 
|  | 49 | template<void (&)(float)> struct t1 {}; | 
|  | 50 | // CHECK: void @_ZN5test52f1ENS_2t1ILZ8test5_f0EEE( | 
|  | 51 | void f1(t1<test5_f0> a0) {} | 
|  | 52 |  | 
|  | 53 | template<int (&)(int)> struct t2 {}; | 
|  | 54 | // CHECK: void @_ZN5test52f2ENS_2t2ILZ4mainEEE | 
|  | 55 | void f2(t2<main> a0) {} | 
|  | 56 | } | 
|  | 57 |  | 
|  | 58 | // FIXME: This fails. | 
|  | 59 | namespace test6 { | 
|  | 60 | struct A { void im0(float); }; | 
|  | 61 | // CHECK: void @_ZN5test61A3im0Ef | 
|  | 62 | void A::im0(float) {} | 
|  | 63 | template <void(A::*)(float)> class T { }; | 
|  | 64 | // FIXME: Fails because we don't treat as an expression. | 
|  | 65 | // CHECK-FAIL: void @_ZN5test62f0ENS_1TIXadL_ZNS_1A3im0EfEEEE( | 
|  | 66 | void f0(T<&A::im0> a0) {} | 
|  | 67 | } | 
| Douglas Gregor | 5610db6 | 2010-02-28 21:40:32 +0000 | [diff] [blame] | 68 |  | 
|  | 69 | namespace test7 { | 
|  | 70 | template<typename T> | 
|  | 71 | struct meta { | 
|  | 72 | static const unsigned value = sizeof(T); | 
|  | 73 | }; | 
|  | 74 |  | 
|  | 75 | template<unsigned> struct int_c { | 
|  | 76 | typedef float type; | 
|  | 77 | }; | 
|  | 78 |  | 
|  | 79 | template<typename T> | 
|  | 80 | struct X { | 
|  | 81 | template<typename U> | 
|  | 82 | X(U*, typename int_c<(meta<T>::value + meta<U>::value)>::type *) { } | 
|  | 83 | }; | 
|  | 84 |  | 
| Stephen Lin | 9dc6eef | 2013-06-30 20:40:16 +0000 | [diff] [blame] | 85 | // CHECK: define weak_odr {{.*}} @_ZN5test71XIiEC1IdEEPT_PNS_5int_cIXplL_ZNS_4metaIiE5valueEEsr4metaIS3_EE5valueEE4typeE( | 
| Douglas Gregor | 5610db6 | 2010-02-28 21:40:32 +0000 | [diff] [blame] | 86 | template X<int>::X(double*, float*); | 
|  | 87 | } | 
| Douglas Gregor | a51c674 | 2010-02-28 22:05:49 +0000 | [diff] [blame] | 88 |  | 
|  | 89 | namespace test8 { | 
|  | 90 | template<typename T> | 
|  | 91 | struct meta { | 
|  | 92 | struct type { | 
|  | 93 | static const unsigned value = sizeof(T); | 
|  | 94 | }; | 
|  | 95 | }; | 
|  | 96 |  | 
|  | 97 | template<unsigned> struct int_c { | 
|  | 98 | typedef float type; | 
|  | 99 | }; | 
|  | 100 |  | 
|  | 101 | template<typename T> | 
|  | 102 | void f(int_c<meta<T>::type::value>) { } | 
|  | 103 |  | 
| Stephen Lin | 4362261 | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 104 | // CHECK-LABEL: define weak_odr void @_ZN5test81fIiEEvNS_5int_cIXsr4metaIT_E4typeE5valueEEE( | 
| Douglas Gregor | a51c674 | 2010-02-28 22:05:49 +0000 | [diff] [blame] | 105 | template void f<int>(int_c<sizeof(int)>); | 
|  | 106 | } | 
| Douglas Gregor | 1736271 | 2010-04-23 03:10:43 +0000 | [diff] [blame] | 107 |  | 
|  | 108 | namespace test9 { | 
|  | 109 | template<typename T> | 
|  | 110 | struct supermeta { | 
|  | 111 | template<typename U> | 
|  | 112 | struct apply { | 
|  | 113 | typedef T U::*type; | 
|  | 114 | }; | 
|  | 115 | }; | 
|  | 116 |  | 
|  | 117 | struct X { }; | 
|  | 118 |  | 
|  | 119 | template<typename T, typename U> | 
|  | 120 | typename supermeta<T>::template apply<U>::type f(); | 
|  | 121 |  | 
|  | 122 | void test_f() { | 
|  | 123 | // CHECK: @_ZN5test91fIiNS_1XEEENS_9supermetaIT_E5applyIT0_E4typeEv() | 
|  | 124 | // Note: GCC incorrectly mangles this as | 
|  | 125 | // _ZN5test91fIiNS_1XEEENS_9supermetaIT_E5apply4typeEv, while EDG | 
|  | 126 | // gets it right. | 
|  | 127 | f<int, X>(); | 
|  | 128 | } | 
|  | 129 | } | 
| Douglas Gregor | 7988def | 2010-04-28 05:58:56 +0000 | [diff] [blame] | 130 |  | 
|  | 131 | namespace test10 { | 
|  | 132 | template<typename T> | 
|  | 133 | struct X { | 
|  | 134 | template<typename U> | 
|  | 135 | struct definition { | 
|  | 136 | }; | 
|  | 137 | }; | 
|  | 138 |  | 
|  | 139 | // CHECK: _ZN6test101fIidEENS_1XIT_E10definitionIT0_EES2_S5_ | 
|  | 140 | template<typename T, typename U> | 
|  | 141 | typename X<T>::template definition<U> f(T, U) { } | 
|  | 142 |  | 
|  | 143 | void g(int i, double d) { | 
|  | 144 | f(i, d); | 
|  | 145 | } | 
|  | 146 | } | 
| John McCall | 8ba2f20 | 2012-01-06 05:06:35 +0000 | [diff] [blame] | 147 |  | 
|  | 148 | // Report from Jason Merrill on cxx-abi-dev, 2012.01.04. | 
|  | 149 | namespace test11 { | 
|  | 150 | int cmp(char a, char b); | 
|  | 151 | template <typename T, int (*cmp)(T, T)> struct A {}; | 
|  | 152 | template <typename T> void f(A<T,cmp> &) {} | 
|  | 153 | template void f<char>(A<char,cmp> &); | 
|  | 154 | // CHECK: @_ZN6test111fIcEEvRNS_1AIT_L_ZNS_3cmpEccEEE( | 
|  | 155 | } | 
| Richard Smith | 9380e0e | 2012-04-04 21:11:30 +0000 | [diff] [blame] | 156 |  | 
|  | 157 | namespace test12 { | 
|  | 158 | // Make sure we can mangle non-type template args with internal linkage. | 
|  | 159 | static int f(); | 
|  | 160 | const int n = 10; | 
|  | 161 | template<typename T, T v> void test() {} | 
|  | 162 | void use() { | 
| Stephen Lin | 4362261 | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 163 | // CHECK-LABEL: define internal void @_ZN6test124testIFivEXadL_ZNS_L1fEvEEEEvv( | 
| Richard Smith | 9380e0e | 2012-04-04 21:11:30 +0000 | [diff] [blame] | 164 | test<int(), &f>(); | 
| Stephen Lin | 4362261 | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 165 | // CHECK-LABEL: define internal void @_ZN6test124testIRFivELZNS_L1fEvEEEvv( | 
| Richard Smith | 9380e0e | 2012-04-04 21:11:30 +0000 | [diff] [blame] | 166 | test<int(&)(), f>(); | 
| Stephen Lin | 4362261 | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 167 | // CHECK-LABEL: define internal void @_ZN6test124testIPKiXadL_ZNS_L1nEEEEEvv( | 
| Richard Smith | 9380e0e | 2012-04-04 21:11:30 +0000 | [diff] [blame] | 168 | test<const int*, &n>(); | 
| Stephen Lin | 4362261 | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 169 | // CHECK-LABEL: define internal void @_ZN6test124testIRKiLZNS_L1nEEEEvv( | 
| Richard Smith | 9380e0e | 2012-04-04 21:11:30 +0000 | [diff] [blame] | 170 | test<const int&, n>(); | 
|  | 171 | } | 
|  | 172 | } | 
| John McCall | dd61f2e | 2012-08-18 04:51:52 +0000 | [diff] [blame] | 173 |  | 
|  | 174 | // rdar://problem/12072531 | 
|  | 175 | // Test the boundary condition of minimal signed integers. | 
|  | 176 | namespace test13 { | 
|  | 177 | template <char c> char returnChar() { return c; } | 
|  | 178 | template char returnChar<-128>(); | 
|  | 179 | // CHECK: @_ZN6test1310returnCharILcn128EEEcv() | 
|  | 180 |  | 
|  | 181 | template <short s> short returnShort() { return s; } | 
|  | 182 | template short returnShort<-32768>(); | 
|  | 183 | // CHECK: @_ZN6test1311returnShortILsn32768EEEsv() | 
|  | 184 | } |