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