blob: 4b64f51143df662d5cea2e23501fb4bb4a4a91f2 [file] [log] [blame]
Sebastian Redl9617e7e2010-08-24 00:50:16 +00001// Test C++ chained PCH functionality
2
3// Without PCH
Andrew Trickba266ee2010-10-19 21:54:32 +00004// RUN: %clang_cc1 -fsyntax-only -verify -include %s -include %s %s
Sebastian Redl9617e7e2010-08-24 00:50:16 +00005
6// With PCH
Argyrios Kyrtzidis35dcda72011-03-09 17:21:42 +00007// RUN: %clang_cc1 -fsyntax-only -verify %s -chain-include %s -chain-include %s
Sebastian Redl9617e7e2010-08-24 00:50:16 +00008
Andy Gibbsc6e68da2012-10-19 12:44:48 +00009// expected-no-diagnostics
10
Andrew Trickba266ee2010-10-19 21:54:32 +000011#ifndef HEADER1
12#define HEADER1
13//===----------------------------------------------------------------------===//
14// Primary header for C++ chained PCH test
15
16void f();
17
18// Name not appearing in dependent
19void pf();
20
21namespace ns {
22 void g();
23
24 void pg();
25}
26
27template <typename T>
28struct S { typedef int G; };
29
30// Partially specialize
31template <typename T>
32struct S<T *> { typedef int H; };
33
Argyrios Kyrtzidisa41f6602010-10-20 00:11:15 +000034template <typename T> struct TS2;
35typedef TS2<int> TS2int;
36
Anders Carlsson1f13bb52011-03-09 05:09:32 +000037template <typename T> struct TestBaseSpecifiers { };
38template<typename T> struct TestBaseSpecifiers2 : TestBaseSpecifiers<T> { };
39
Sebastian Redl2ac2c722011-04-29 08:19:30 +000040template <typename T>
41struct TS3 {
42 static const int value = 0;
Richard Smithed2974f2011-12-21 00:25:33 +000043 static const int value2;
Sebastian Redl2ac2c722011-04-29 08:19:30 +000044};
45template <typename T>
46const int TS3<T>::value;
Richard Smithed2974f2011-12-21 00:25:33 +000047template <typename T>
48const int TS3<T>::value2 = 1;
Sebastian Redl2ac2c722011-04-29 08:19:30 +000049// Instantiate struct, but not value.
50struct instantiate : TS3<int> {};
51
Douglas Gregor05f10352011-12-17 23:38:30 +000052// Typedef
53typedef int Integer;
Sebastian Redl2ac2c722011-04-29 08:19:30 +000054
Andrew Trickba266ee2010-10-19 21:54:32 +000055//===----------------------------------------------------------------------===//
56#elif not defined(HEADER2)
57#define HEADER2
Sebastian Redl2ac2c722011-04-29 08:19:30 +000058#if !defined(HEADER1)
59#error Header inclusion order messed up
60#endif
61
Andrew Trickba266ee2010-10-19 21:54:32 +000062//===----------------------------------------------------------------------===//
63// Dependent header for C++ chained PCH test
64
65// Overload function from primary
66void f(int);
67
68// Add function with different name
69void f2();
70
71// Reopen namespace
72namespace ns {
73 // Overload function from primary
74 void g(int);
75
76 // Add different name
77 void g2();
78}
79
80// Specialize template from primary
81template <>
82struct S<int> { typedef int I; };
83
84// Partially specialize
85template <typename T>
86struct S<T &> { typedef int J; };
87
88// Specialize previous partial specialization
89template <>
90struct S<int *> { typedef int K; };
91
92// Specialize the partial specialization from this file
93template <>
94struct S<int &> { typedef int L; };
95
Argyrios Kyrtzidisa41f6602010-10-20 00:11:15 +000096template <typename T> struct TS2 { };
97
Anders Carlsson1f13bb52011-03-09 05:09:32 +000098struct TestBaseSpecifiers3 { };
99struct TestBaseSpecifiers4 : TestBaseSpecifiers3 { };
100
Anders Carlsson9bb83e82011-03-06 18:41:18 +0000101struct A { };
102struct B : A { };
103
Richard Smithed2974f2011-12-21 00:25:33 +0000104// Instantiate TS3's members.
Sebastian Redl2ac2c722011-04-29 08:19:30 +0000105static const int ts3m1 = TS3<int>::value;
Richard Smithed2974f2011-12-21 00:25:33 +0000106extern int arr[TS3<int>::value2];
Sebastian Redl2ac2c722011-04-29 08:19:30 +0000107
Douglas Gregor05f10352011-12-17 23:38:30 +0000108// Redefinition of typedef
109typedef int Integer;
110
Andrew Trickba266ee2010-10-19 21:54:32 +0000111//===----------------------------------------------------------------------===//
112#else
113//===----------------------------------------------------------------------===//
114
Sebastian Redl9617e7e2010-08-24 00:50:16 +0000115void test() {
116 f();
117 f(1);
118 pf();
119 f2();
120
121 ns::g();
122 ns::g(1);
123 ns::pg();
124 ns::g2();
125
Sebastian Redl401b39a2010-08-24 22:50:24 +0000126 typedef S<double>::G T1;
127 typedef S<double *>::H T2;
128 typedef S<int>::I T3;
129 typedef S<double &>::J T4;
130 typedef S<int *>::K T5;
131 typedef S<int &>::L T6;
Argyrios Kyrtzidisa41f6602010-10-20 00:11:15 +0000132
133 TS2int ts2;
Anders Carlsson9bb83e82011-03-06 18:41:18 +0000134
135 B b;
Douglas Gregor05f10352011-12-17 23:38:30 +0000136 Integer i = 17;
Sebastian Redl9617e7e2010-08-24 00:50:16 +0000137}
Andrew Trickba266ee2010-10-19 21:54:32 +0000138
Sebastian Redl2ac2c722011-04-29 08:19:30 +0000139// Should have remembered that there is a definition.
140static const int ts3m2 = TS3<int>::value;
Richard Smithed2974f2011-12-21 00:25:33 +0000141int arr[TS3<int>::value2];
Sebastian Redl2ac2c722011-04-29 08:19:30 +0000142
Andrew Trickba266ee2010-10-19 21:54:32 +0000143//===----------------------------------------------------------------------===//
144#endif