blob: af0a23afea9f1b06519b26ff1937a038e0040ff5 [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
47
Andrew Trick220a9c82010-10-19 21:54:32 +000048//===----------------------------------------------------------------------===//
49#elif not defined(HEADER2)
50#define HEADER2
Sebastian Redlf79a7192011-04-29 08:19:30 +000051#if !defined(HEADER1)
52#error Header inclusion order messed up
53#endif
54
Andrew Trick220a9c82010-10-19 21:54:32 +000055//===----------------------------------------------------------------------===//
56// Dependent header for C++ chained PCH test
57
58// Overload function from primary
59void f(int);
60
61// Add function with different name
62void f2();
63
64// Reopen namespace
65namespace ns {
66 // Overload function from primary
67 void g(int);
68
69 // Add different name
70 void g2();
71}
72
73// Specialize template from primary
74template <>
75struct S<int> { typedef int I; };
76
77// Partially specialize
78template <typename T>
79struct S<T &> { typedef int J; };
80
81// Specialize previous partial specialization
82template <>
83struct S<int *> { typedef int K; };
84
85// Specialize the partial specialization from this file
86template <>
87struct S<int &> { typedef int L; };
88
Argyrios Kyrtzidis9703b0d2010-10-20 00:11:15 +000089template <typename T> struct TS2 { };
90
Anders Carlssonf25330b2011-03-09 05:09:32 +000091struct TestBaseSpecifiers3 { };
92struct TestBaseSpecifiers4 : TestBaseSpecifiers3 { };
93
Anders Carlssonc8505782011-03-06 18:41:18 +000094struct A { };
95struct B : A { };
96
Sebastian Redlf79a7192011-04-29 08:19:30 +000097// Instantiate TS3's member.
98static const int ts3m1 = TS3<int>::value;
99
Andrew Trick220a9c82010-10-19 21:54:32 +0000100//===----------------------------------------------------------------------===//
101#else
102//===----------------------------------------------------------------------===//
103
Sebastian Redl5967d622010-08-24 00:50:16 +0000104void test() {
105 f();
106 f(1);
107 pf();
108 f2();
109
110 ns::g();
111 ns::g(1);
112 ns::pg();
113 ns::g2();
114
Sebastian Redl4153a062010-08-24 22:50:24 +0000115 typedef S<double>::G T1;
116 typedef S<double *>::H T2;
117 typedef S<int>::I T3;
118 typedef S<double &>::J T4;
119 typedef S<int *>::K T5;
120 typedef S<int &>::L T6;
Argyrios Kyrtzidis9703b0d2010-10-20 00:11:15 +0000121
122 TS2int ts2;
Anders Carlssonc8505782011-03-06 18:41:18 +0000123
124 B b;
Sebastian Redl5967d622010-08-24 00:50:16 +0000125}
Andrew Trick220a9c82010-10-19 21:54:32 +0000126
Sebastian Redlf79a7192011-04-29 08:19:30 +0000127// Should have remembered that there is a definition.
128static const int ts3m2 = TS3<int>::value;
129
Andrew Trick220a9c82010-10-19 21:54:32 +0000130//===----------------------------------------------------------------------===//
131#endif