David Majnemer | 192d179 | 2013-11-27 08:20:38 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -verify -std=c++11 %s |
Andy Gibbs | c6e68da | 2012-10-19 12:44:48 +0000 | [diff] [blame] | 2 | // expected-no-diagnostics |
Douglas Gregor | f5974fa | 2010-01-16 20:21:20 +0000 | [diff] [blame] | 3 | template<typename T> |
| 4 | void f0() { |
| 5 | struct X; |
| 6 | typedef struct Y { |
| 7 | T (X::* f1())(int) { return 0; } |
| 8 | } Y2; |
| 9 | |
| 10 | Y2 y = Y(); |
| 11 | } |
| 12 | |
| 13 | template void f0<int>(); |
Douglas Gregor | edf8f39 | 2010-01-16 20:52:59 +0000 | [diff] [blame] | 14 | |
| 15 | // PR5764 |
| 16 | namespace PR5764 { |
John McCall | 3155f57 | 2010-04-09 19:03:51 +0000 | [diff] [blame] | 17 | struct X { |
Douglas Gregor | edf8f39 | 2010-01-16 20:52:59 +0000 | [diff] [blame] | 18 | template <typename T> |
| 19 | void Bar() { |
Douglas Gregor | 7f792cf | 2010-01-16 22:29:39 +0000 | [diff] [blame] | 20 | typedef T ValueType; |
John McCall | 3155f57 | 2010-04-09 19:03:51 +0000 | [diff] [blame] | 21 | struct Y { |
Douglas Gregor | 7f792cf | 2010-01-16 22:29:39 +0000 | [diff] [blame] | 22 | Y() { V = ValueType(); } |
| 23 | |
| 24 | ValueType V; |
Douglas Gregor | edf8f39 | 2010-01-16 20:52:59 +0000 | [diff] [blame] | 25 | }; |
| 26 | |
| 27 | Y y; |
| 28 | } |
| 29 | }; |
| 30 | |
| 31 | void test(X x) { |
| 32 | x.Bar<int>(); |
| 33 | } |
| 34 | } |
| 35 | |
Chandler Carruth | 3e0c140 | 2010-02-15 22:12:26 +0000 | [diff] [blame] | 36 | // Instantiation of local classes with virtual functions. |
| 37 | namespace local_class_with_virtual_functions { |
| 38 | template <typename T> struct X { }; |
| 39 | template <typename T> struct Y { }; |
| 40 | |
| 41 | template <typename T> |
| 42 | void f() { |
| 43 | struct Z : public X<Y<T>*> { |
| 44 | virtual void g(Y<T>* y) { } |
| 45 | void g2(int x) {(void)x;} |
| 46 | }; |
| 47 | Z z; |
| 48 | (void)z; |
| 49 | } |
| 50 | |
| 51 | struct S { }; |
| 52 | void test() { f<S>(); } |
| 53 | } |
Douglas Gregor | e9fc8dc | 2010-12-21 21:22:51 +0000 | [diff] [blame] | 54 | |
| 55 | namespace PR8801 { |
| 56 | template<typename T> |
| 57 | void foo() { |
| 58 | class X; |
Douglas Gregor | 7f6ae69 | 2010-12-21 21:40:41 +0000 | [diff] [blame] | 59 | typedef int (X::*pmf_type)(); |
Douglas Gregor | e9fc8dc | 2010-12-21 21:22:51 +0000 | [diff] [blame] | 60 | class X : public T { }; |
Douglas Gregor | 7f6ae69 | 2010-12-21 21:40:41 +0000 | [diff] [blame] | 61 | |
| 62 | pmf_type pmf = &T::foo; |
Douglas Gregor | e9fc8dc | 2010-12-21 21:22:51 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Douglas Gregor | 7f6ae69 | 2010-12-21 21:40:41 +0000 | [diff] [blame] | 65 | struct Y { int foo(); }; |
Douglas Gregor | e9fc8dc | 2010-12-21 21:22:51 +0000 | [diff] [blame] | 66 | |
| 67 | template void foo<Y>(); |
| 68 | } |
David Majnemer | 192d179 | 2013-11-27 08:20:38 +0000 | [diff] [blame] | 69 | |
| 70 | namespace TemplatePacksAndLambdas { |
| 71 | template <typename ...T> int g(T...); |
| 72 | struct S { |
| 73 | template <typename ...T> static void f(int f = g([]{ static T t; return ++t; }()...)) {} |
| 74 | }; |
| 75 | void h() { S::f<int, int, int>(); } |
| 76 | } |
| 77 | |
| 78 | namespace PR9685 { |
| 79 | template <class Thing> void forEach(Thing t) { t.func(); } |
| 80 | |
| 81 | template <typename T> void doIt() { |
| 82 | struct Functor { |
| 83 | void func() { (void)i; } |
| 84 | int i; |
| 85 | }; |
| 86 | |
| 87 | forEach(Functor()); |
| 88 | } |
| 89 | |
| 90 | void call() { |
| 91 | doIt<int>(); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | namespace PR12702 { |
| 96 | struct S { |
| 97 | template <typename F> bool apply(F f) { return f(); } |
| 98 | }; |
| 99 | |
| 100 | template <typename> struct T { |
| 101 | void foo() { |
| 102 | struct F { |
| 103 | int x; |
| 104 | |
| 105 | bool operator()() { return x == 0; } |
| 106 | }; |
| 107 | |
| 108 | S().apply(F()); |
| 109 | } |
| 110 | }; |
| 111 | |
| 112 | void call() { T<int>().foo(); } |
| 113 | } |
| 114 | |
| 115 | namespace PR17139 { |
| 116 | template <class T> void foo(const T &t) { t.foo(); } |
| 117 | |
| 118 | template <class F> void bar(F *f) { |
| 119 | struct B { |
| 120 | F *fn; |
| 121 | void foo() const { fn(); } |
| 122 | } b = { f }; |
| 123 | foo(b); |
| 124 | } |
| 125 | |
| 126 | void go() {} |
| 127 | |
| 128 | void test() { bar(go); } |
| 129 | } |
| 130 | |
| 131 | namespace PR17740 { |
| 132 | class C { |
| 133 | public: |
| 134 | template <typename T> static void foo(T function); |
| 135 | template <typename T> static void bar(T function); |
| 136 | template <typename T> static void func(T function); |
| 137 | }; |
| 138 | |
| 139 | template <typename T> void C::foo(T function) { function(); } |
| 140 | |
| 141 | template <typename T> void C::bar(T function) { |
| 142 | foo([&function]() { function(); }); |
| 143 | } |
| 144 | |
| 145 | template <typename T> void C::func(T function) { |
| 146 | struct Struct { |
| 147 | T mFunction; |
| 148 | |
| 149 | Struct(T function) : mFunction(function) {}; |
| 150 | |
| 151 | void operator()() { |
| 152 | mFunction(); |
| 153 | }; |
| 154 | }; |
| 155 | |
| 156 | bar(Struct(function)); |
| 157 | } |
| 158 | |
| 159 | void call() { |
| 160 | C::func([]() {}); |
| 161 | } |
| 162 | } |