• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Test C++ chained PCH functionality
2 
3 // Without PCH
4 // RUN: %clang_cc1 -fsyntax-only -verify -include %s -include %s %s
5 
6 // With PCH
7 // RUN: %clang_cc1 -fsyntax-only -verify %s -chain-include %s -chain-include %s
8 
9 #ifndef HEADER1
10 #define HEADER1
11 //===----------------------------------------------------------------------===//
12 // Primary header for C++ chained PCH test
13 
14 void f();
15 
16 // Name not appearing in dependent
17 void pf();
18 
19 namespace ns {
20   void g();
21 
22   void pg();
23 }
24 
25 template <typename T>
26 struct S { typedef int G; };
27 
28 // Partially specialize
29 template <typename T>
30 struct S<T *> { typedef int H; };
31 
32 template <typename T> struct TS2;
33 typedef TS2<int> TS2int;
34 
35 template <typename T> struct TestBaseSpecifiers { };
36 template<typename T> struct TestBaseSpecifiers2 : TestBaseSpecifiers<T> { };
37 
38 template <typename T>
39 struct TS3 {
40   static const int value = 0;
41   static const int value2;
42 };
43 template <typename T>
44 const int TS3<T>::value;
45 template <typename T>
46 const int TS3<T>::value2 = 1;
47 // Instantiate struct, but not value.
48 struct instantiate : TS3<int> {};
49 
50 // Typedef
51 typedef int Integer;
52 
53 //===----------------------------------------------------------------------===//
54 #elif not defined(HEADER2)
55 #define HEADER2
56 #if !defined(HEADER1)
57 #error Header inclusion order messed up
58 #endif
59 
60 //===----------------------------------------------------------------------===//
61 // Dependent header for C++ chained PCH test
62 
63 // Overload function from primary
64 void f(int);
65 
66 // Add function with different name
67 void f2();
68 
69 // Reopen namespace
70 namespace 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
79 template <>
80 struct S<int> { typedef int I; };
81 
82 // Partially specialize
83 template <typename T>
84 struct S<T &> { typedef int J; };
85 
86 // Specialize previous partial specialization
87 template <>
88 struct S<int *> { typedef int K; };
89 
90 // Specialize the partial specialization from this file
91 template <>
92 struct S<int &> { typedef int L; };
93 
94 template <typename T> struct TS2 { };
95 
96 struct TestBaseSpecifiers3 { };
97 struct TestBaseSpecifiers4 : TestBaseSpecifiers3 { };
98 
99 struct A { };
100 struct B : A { };
101 
102 // Instantiate TS3's members.
103 static const int ts3m1 = TS3<int>::value;
104 extern int arr[TS3<int>::value2];
105 
106 // Redefinition of typedef
107 typedef int Integer;
108 
109 //===----------------------------------------------------------------------===//
110 #else
111 //===----------------------------------------------------------------------===//
112 
test()113 void 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 
124   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;
130 
131   TS2int ts2;
132 
133   B b;
134   Integer i = 17;
135 }
136 
137 // Should have remembered that there is a definition.
138 static const int ts3m2 = TS3<int>::value;
139 int arr[TS3<int>::value2];
140 
141 //===----------------------------------------------------------------------===//
142 #endif
143