blob: c42ee7d39eeb8012bf44fce285062d6a96199388 [file] [log] [blame]
Sebastian Redl5967d622010-08-24 00:50:16 +00001// Test C++ chained PCH functionality
2
3// Without PCH
Andrew Trick220a9c82010-10-19 21:54:32 +00004// RUN: %clang_cc1 -fsyntax-only -verify -include %s -include %s %s
Sebastian Redl5967d622010-08-24 00:50:16 +00005
6// With PCH
Argyrios Kyrtzidisb0f4b9a2011-03-09 17:21:42 +00007// RUN: %clang_cc1 -fsyntax-only -verify %s -chain-include %s -chain-include %s
Sebastian Redl5967d622010-08-24 00:50:16 +00008
Andrew Trick220a9c82010-10-19 21:54:32 +00009#ifndef HEADER1
10#define HEADER1
11//===----------------------------------------------------------------------===//
12// Primary header for C++ chained PCH test
13
14void f();
15
16// Name not appearing in dependent
17void pf();
18
19namespace ns {
20 void g();
21
22 void pg();
23}
24
25template <typename T>
26struct S { typedef int G; };
27
28// Partially specialize
29template <typename T>
30struct S<T *> { typedef int H; };
31
Argyrios Kyrtzidis9703b0d2010-10-20 00:11:15 +000032template <typename T> struct TS2;
33typedef TS2<int> TS2int;
34
Anders Carlssonf25330b2011-03-09 05:09:32 +000035template <typename T> struct TestBaseSpecifiers { };
36template<typename T> struct TestBaseSpecifiers2 : TestBaseSpecifiers<T> { };
37
Sebastian Redlf79a7192011-04-29 08:19:30 +000038template <typename T>
39struct TS3 {
40 static const int value = 0;
41};
42template <typename T>
43const int TS3<T>::value;
44// Instantiate struct, but not value.
45struct instantiate : TS3<int> {};
46
Douglas Gregora1be2782011-12-17 23:38:30 +000047// Typedef
48typedef int Integer;
Sebastian Redlf79a7192011-04-29 08:19:30 +000049
Andrew Trick220a9c82010-10-19 21:54:32 +000050//===----------------------------------------------------------------------===//
51#elif not defined(HEADER2)
52#define HEADER2
Sebastian Redlf79a7192011-04-29 08:19:30 +000053#if !defined(HEADER1)
54#error Header inclusion order messed up
55#endif
56
Andrew Trick220a9c82010-10-19 21:54:32 +000057//===----------------------------------------------------------------------===//
58// Dependent header for C++ chained PCH test
59
60// Overload function from primary
61void f(int);
62
63// Add function with different name
64void f2();
65
66// Reopen namespace
67namespace ns {
68 // Overload function from primary
69 void g(int);
70
71 // Add different name
72 void g2();
73}
74
75// Specialize template from primary
76template <>
77struct S<int> { typedef int I; };
78
79// Partially specialize
80template <typename T>
81struct S<T &> { typedef int J; };
82
83// Specialize previous partial specialization
84template <>
85struct S<int *> { typedef int K; };
86
87// Specialize the partial specialization from this file
88template <>
89struct S<int &> { typedef int L; };
90
Argyrios Kyrtzidis9703b0d2010-10-20 00:11:15 +000091template <typename T> struct TS2 { };
92
Anders Carlssonf25330b2011-03-09 05:09:32 +000093struct TestBaseSpecifiers3 { };
94struct TestBaseSpecifiers4 : TestBaseSpecifiers3 { };
95
Anders Carlssonc8505782011-03-06 18:41:18 +000096struct A { };
97struct B : A { };
98
Sebastian Redlf79a7192011-04-29 08:19:30 +000099// Instantiate TS3's member.
100static const int ts3m1 = TS3<int>::value;
101
Douglas Gregora1be2782011-12-17 23:38:30 +0000102// Redefinition of typedef
103typedef int Integer;
104
Andrew Trick220a9c82010-10-19 21:54:32 +0000105//===----------------------------------------------------------------------===//
106#else
107//===----------------------------------------------------------------------===//
108
Sebastian Redl5967d622010-08-24 00:50:16 +0000109void test() {
110 f();
111 f(1);
112 pf();
113 f2();
114
115 ns::g();
116 ns::g(1);
117 ns::pg();
118 ns::g2();
119
Sebastian Redl4153a062010-08-24 22:50:24 +0000120 typedef S<double>::G T1;
121 typedef S<double *>::H T2;
122 typedef S<int>::I T3;
123 typedef S<double &>::J T4;
124 typedef S<int *>::K T5;
125 typedef S<int &>::L T6;
Argyrios Kyrtzidis9703b0d2010-10-20 00:11:15 +0000126
127 TS2int ts2;
Anders Carlssonc8505782011-03-06 18:41:18 +0000128
129 B b;
Douglas Gregora1be2782011-12-17 23:38:30 +0000130 Integer i = 17;
Sebastian Redl5967d622010-08-24 00:50:16 +0000131}
Andrew Trick220a9c82010-10-19 21:54:32 +0000132
Sebastian Redlf79a7192011-04-29 08:19:30 +0000133// Should have remembered that there is a definition.
134static const int ts3m2 = TS3<int>::value;
135
Andrew Trick220a9c82010-10-19 21:54:32 +0000136//===----------------------------------------------------------------------===//
137#endif