blob: 2b5db0fda3ece947e6eb9774c4eb7c2c6ef7b46e [file] [log] [blame]
David Majnemer192d1792013-11-27 08:20:38 +00001// RUN: %clang_cc1 -verify -std=c++11 %s
Andy Gibbsc6e68da2012-10-19 12:44:48 +00002// expected-no-diagnostics
Douglas Gregorf5974fa2010-01-16 20:21:20 +00003template<typename T>
4void f0() {
5 struct X;
6 typedef struct Y {
7 T (X::* f1())(int) { return 0; }
8 } Y2;
9
10 Y2 y = Y();
11}
12
13template void f0<int>();
Douglas Gregoredf8f392010-01-16 20:52:59 +000014
15// PR5764
16namespace PR5764 {
John McCall3155f572010-04-09 19:03:51 +000017 struct X {
Douglas Gregoredf8f392010-01-16 20:52:59 +000018 template <typename T>
19 void Bar() {
Douglas Gregor7f792cf2010-01-16 22:29:39 +000020 typedef T ValueType;
John McCall3155f572010-04-09 19:03:51 +000021 struct Y {
Douglas Gregor7f792cf2010-01-16 22:29:39 +000022 Y() { V = ValueType(); }
23
24 ValueType V;
Douglas Gregoredf8f392010-01-16 20:52:59 +000025 };
26
27 Y y;
28 }
29 };
30
31 void test(X x) {
32 x.Bar<int>();
33 }
34}
35
Chandler Carruth3e0c1402010-02-15 22:12:26 +000036// Instantiation of local classes with virtual functions.
37namespace 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 Gregore9fc8dc2010-12-21 21:22:51 +000054
55namespace PR8801 {
56 template<typename T>
57 void foo() {
58 class X;
Douglas Gregor7f6ae692010-12-21 21:40:41 +000059 typedef int (X::*pmf_type)();
Douglas Gregore9fc8dc2010-12-21 21:22:51 +000060 class X : public T { };
Douglas Gregor7f6ae692010-12-21 21:40:41 +000061
62 pmf_type pmf = &T::foo;
Douglas Gregore9fc8dc2010-12-21 21:22:51 +000063 }
64
Douglas Gregor7f6ae692010-12-21 21:40:41 +000065 struct Y { int foo(); };
Douglas Gregore9fc8dc2010-12-21 21:22:51 +000066
67 template void foo<Y>();
68}
David Majnemer192d1792013-11-27 08:20:38 +000069
70namespace 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
78namespace 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
95namespace 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
115namespace 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
131namespace PR17740 {
132class C {
133public:
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
139template <typename T> void C::foo(T function) { function(); }
140
141template <typename T> void C::bar(T function) {
142 foo([&function]() { function(); });
143}
144
145template <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
159void call() {
160 C::func([]() {});
161}
162}