Bill Wendling | 57907e5 | 2013-11-28 00:34:08 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -verify -std=c++11 %s |
Douglas Gregor | 79c2278 | 2010-01-16 20:21:20 +0000 | [diff] [blame] | 2 | template<typename T> |
| 3 | void f0() { |
| 4 | struct X; |
| 5 | typedef struct Y { |
| 6 | T (X::* f1())(int) { return 0; } |
| 7 | } Y2; |
| 8 | |
| 9 | Y2 y = Y(); |
| 10 | } |
| 11 | |
| 12 | template void f0<int>(); |
Douglas Gregor | 26997fd | 2010-01-16 20:52:59 +0000 | [diff] [blame] | 13 | |
| 14 | // PR5764 |
| 15 | namespace PR5764 { |
John McCall | 7002f4c | 2010-04-09 19:03:51 +0000 | [diff] [blame] | 16 | struct X { |
Douglas Gregor | 26997fd | 2010-01-16 20:52:59 +0000 | [diff] [blame] | 17 | template <typename T> |
| 18 | void Bar() { |
Douglas Gregor | 60406be | 2010-01-16 22:29:39 +0000 | [diff] [blame] | 19 | typedef T ValueType; |
John McCall | 7002f4c | 2010-04-09 19:03:51 +0000 | [diff] [blame] | 20 | struct Y { |
Douglas Gregor | 60406be | 2010-01-16 22:29:39 +0000 | [diff] [blame] | 21 | Y() { V = ValueType(); } |
| 22 | |
| 23 | ValueType V; |
Douglas Gregor | 26997fd | 2010-01-16 20:52:59 +0000 | [diff] [blame] | 24 | }; |
| 25 | |
| 26 | Y y; |
| 27 | } |
| 28 | }; |
| 29 | |
| 30 | void test(X x) { |
| 31 | x.Bar<int>(); |
| 32 | } |
| 33 | } |
| 34 | |
Chandler Carruth | 17e0f40 | 2010-02-15 22:12:26 +0000 | [diff] [blame] | 35 | // Instantiation of local classes with virtual functions. |
| 36 | namespace local_class_with_virtual_functions { |
| 37 | template <typename T> struct X { }; |
| 38 | template <typename T> struct Y { }; |
| 39 | |
| 40 | template <typename T> |
| 41 | void f() { |
| 42 | struct Z : public X<Y<T>*> { |
| 43 | virtual void g(Y<T>* y) { } |
| 44 | void g2(int x) {(void)x;} |
| 45 | }; |
| 46 | Z z; |
| 47 | (void)z; |
| 48 | } |
| 49 | |
| 50 | struct S { }; |
| 51 | void test() { f<S>(); } |
| 52 | } |
Douglas Gregor | ebb1c56 | 2010-12-21 21:22:51 +0000 | [diff] [blame] | 53 | |
| 54 | namespace PR8801 { |
| 55 | template<typename T> |
| 56 | void foo() { |
| 57 | class X; |
Douglas Gregor | cfddf7b | 2010-12-21 21:40:41 +0000 | [diff] [blame] | 58 | typedef int (X::*pmf_type)(); |
Douglas Gregor | ebb1c56 | 2010-12-21 21:22:51 +0000 | [diff] [blame] | 59 | class X : public T { }; |
Douglas Gregor | cfddf7b | 2010-12-21 21:40:41 +0000 | [diff] [blame] | 60 | |
| 61 | pmf_type pmf = &T::foo; |
Douglas Gregor | ebb1c56 | 2010-12-21 21:22:51 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Douglas Gregor | cfddf7b | 2010-12-21 21:40:41 +0000 | [diff] [blame] | 64 | struct Y { int foo(); }; |
Douglas Gregor | ebb1c56 | 2010-12-21 21:22:51 +0000 | [diff] [blame] | 65 | |
| 66 | template void foo<Y>(); |
| 67 | } |
Bill Wendling | 57907e5 | 2013-11-28 00:34:08 +0000 | [diff] [blame] | 68 | |
| 69 | namespace TemplatePacksAndLambdas { |
| 70 | template <typename ...T> int g(T...); |
| 71 | struct S { |
| 72 | template <typename ...T> static void f(int f = g([]{ static T t; return ++t; }()...)) {} |
| 73 | }; |
| 74 | void h() { S::f<int, int, int>(); } |
| 75 | } |
| 76 | |
| 77 | namespace PR9685 { |
| 78 | template <class Thing> void forEach(Thing t) { t.func(); } |
| 79 | |
| 80 | template <typename T> void doIt() { |
| 81 | struct Functor { |
| 82 | void func() { (void)i; } |
| 83 | int i; |
| 84 | }; |
| 85 | |
| 86 | forEach(Functor()); |
| 87 | } |
| 88 | |
| 89 | void call() { |
| 90 | doIt<int>(); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | namespace PR12702 { |
| 95 | struct S { |
| 96 | template <typename F> bool apply(F f) { return f(); } |
| 97 | }; |
| 98 | |
| 99 | template <typename> struct T { |
| 100 | void foo() { |
| 101 | struct F { |
| 102 | int x; |
| 103 | |
| 104 | bool operator()() { return x == 0; } |
| 105 | }; |
| 106 | |
| 107 | S().apply(F()); |
| 108 | } |
| 109 | }; |
| 110 | |
| 111 | void call() { T<int>().foo(); } |
| 112 | } |
| 113 | |
| 114 | namespace PR17139 { |
| 115 | template <class T> void foo(const T &t) { t.foo(); } |
| 116 | |
| 117 | template <class F> void bar(F *f) { |
| 118 | struct B { |
| 119 | F *fn; |
| 120 | void foo() const { fn(); } |
| 121 | } b = { f }; |
| 122 | foo(b); |
| 123 | } |
| 124 | |
| 125 | void go() {} |
| 126 | |
| 127 | void test() { bar(go); } |
| 128 | } |
| 129 | |
| 130 | namespace PR17740 { |
| 131 | class C { |
| 132 | public: |
| 133 | template <typename T> static void foo(T function); |
| 134 | template <typename T> static void bar(T function); |
| 135 | template <typename T> static void func(T function); |
| 136 | }; |
| 137 | |
| 138 | template <typename T> void C::foo(T function) { function(); } |
| 139 | |
| 140 | template <typename T> void C::bar(T function) { |
| 141 | foo([&function]() { function(); }); |
| 142 | } |
| 143 | |
| 144 | template <typename T> void C::func(T function) { |
| 145 | struct Struct { |
| 146 | T mFunction; |
| 147 | |
| 148 | Struct(T function) : mFunction(function) {}; |
| 149 | |
| 150 | void operator()() { |
| 151 | mFunction(); |
| 152 | }; |
| 153 | }; |
| 154 | |
| 155 | bar(Struct(function)); |
| 156 | } |
| 157 | |
| 158 | void call() { |
| 159 | C::func([]() {}); |
| 160 | } |
| 161 | } |
Bill Wendling | 65173e0 | 2013-11-28 00:34:28 +0000 | [diff] [blame] | 162 | |
| 163 | namespace PR14373 { |
| 164 | struct function { |
| 165 | template <typename _Functor> function(_Functor __f) { __f(); } |
| 166 | }; |
| 167 | template <typename Func> function exec_func(Func f) { |
| 168 | struct functor { |
| 169 | functor(Func f) : func(f) {} |
| 170 | void operator()() const { func(); } |
| 171 | Func func; |
| 172 | }; |
| 173 | return functor(f); |
| 174 | } |
| 175 | struct Type { |
| 176 | void operator()() const {} |
| 177 | }; |
| 178 | int call() { |
| 179 | exec_func(Type()); |
Bill Wendling | 367e846 | 2013-12-01 02:09:57 +0000 | [diff] [blame] | 180 | return 0; |
Bill Wendling | 65173e0 | 2013-11-28 00:34:28 +0000 | [diff] [blame] | 181 | } |
| 182 | } |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 183 | |
| 184 | namespace PR18907 { |
| 185 | template <typename> |
| 186 | class C : public C<int> {}; // expected-error{{within its own definition}} |
| 187 | |
| 188 | template <typename X> |
| 189 | void F() { |
| 190 | struct A : C<X> {}; |
| 191 | } |
| 192 | |
| 193 | struct B { |
| 194 | void f() { F<int>(); } |
| 195 | }; |
| 196 | } |