blob: 0d50e61c5a956f426d538903a139bbf53eba3726 [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;
Richard Smith3e9ea0b2011-12-21 00:25:33 +000041 static const int value2;
Sebastian Redlf79a7192011-04-29 08:19:30 +000042};
43template <typename T>
44const int TS3<T>::value;
Richard Smith3e9ea0b2011-12-21 00:25:33 +000045template <typename T>
46const int TS3<T>::value2 = 1;
Sebastian Redlf79a7192011-04-29 08:19:30 +000047// Instantiate struct, but not value.
48struct instantiate : TS3<int> {};
49
Douglas Gregora1be2782011-12-17 23:38:30 +000050// Typedef
51typedef int Integer;
Sebastian Redlf79a7192011-04-29 08:19:30 +000052
Andrew Trick220a9c82010-10-19 21:54:32 +000053//===----------------------------------------------------------------------===//
54#elif not defined(HEADER2)
55#define HEADER2
Sebastian Redlf79a7192011-04-29 08:19:30 +000056#if !defined(HEADER1)
57#error Header inclusion order messed up
58#endif
59
Andrew Trick220a9c82010-10-19 21:54:32 +000060//===----------------------------------------------------------------------===//
61// Dependent header for C++ chained PCH test
62
63// Overload function from primary
64void f(int);
65
66// Add function with different name
67void f2();
68
69// Reopen namespace
70namespace ns {
71 // Overload function from primary
72 void g(int);
73
74 // Add different name
75 void g2();
76}
77
78// Specialize template from primary
79template <>
80struct S<int> { typedef int I; };
81
82// Partially specialize
83template <typename T>
84struct S<T &> { typedef int J; };
85
86// Specialize previous partial specialization
87template <>
88struct S<int *> { typedef int K; };
89
90// Specialize the partial specialization from this file
91template <>
92struct S<int &> { typedef int L; };
93
Argyrios Kyrtzidis9703b0d2010-10-20 00:11:15 +000094template <typename T> struct TS2 { };
95
Anders Carlssonf25330b2011-03-09 05:09:32 +000096struct TestBaseSpecifiers3 { };
97struct TestBaseSpecifiers4 : TestBaseSpecifiers3 { };
98
Anders Carlssonc8505782011-03-06 18:41:18 +000099struct A { };
100struct B : A { };
101
Richard Smith3e9ea0b2011-12-21 00:25:33 +0000102// Instantiate TS3's members.
Sebastian Redlf79a7192011-04-29 08:19:30 +0000103static const int ts3m1 = TS3<int>::value;
Richard Smith3e9ea0b2011-12-21 00:25:33 +0000104extern int arr[TS3<int>::value2];
Sebastian Redlf79a7192011-04-29 08:19:30 +0000105
Douglas Gregora1be2782011-12-17 23:38:30 +0000106// Redefinition of typedef
107typedef int Integer;
108
Andrew Trick220a9c82010-10-19 21:54:32 +0000109//===----------------------------------------------------------------------===//
110#else
111//===----------------------------------------------------------------------===//
112
Sebastian Redl5967d622010-08-24 00:50:16 +0000113void test() {
114 f();
115 f(1);
116 pf();
117 f2();
118
119 ns::g();
120 ns::g(1);
121 ns::pg();
122 ns::g2();
123
Sebastian Redl4153a062010-08-24 22:50:24 +0000124 typedef S<double>::G T1;
125 typedef S<double *>::H T2;
126 typedef S<int>::I T3;
127 typedef S<double &>::J T4;
128 typedef S<int *>::K T5;
129 typedef S<int &>::L T6;
Argyrios Kyrtzidis9703b0d2010-10-20 00:11:15 +0000130
131 TS2int ts2;
Anders Carlssonc8505782011-03-06 18:41:18 +0000132
133 B b;
Douglas Gregora1be2782011-12-17 23:38:30 +0000134 Integer i = 17;
Sebastian Redl5967d622010-08-24 00:50:16 +0000135}
Andrew Trick220a9c82010-10-19 21:54:32 +0000136
Sebastian Redlf79a7192011-04-29 08:19:30 +0000137// Should have remembered that there is a definition.
138static const int ts3m2 = TS3<int>::value;
Richard Smith3e9ea0b2011-12-21 00:25:33 +0000139int arr[TS3<int>::value2];
Sebastian Redlf79a7192011-04-29 08:19:30 +0000140
Andrew Trick220a9c82010-10-19 21:54:32 +0000141//===----------------------------------------------------------------------===//
142#endif