blob: 6e9c1743fbd7e3a59b89d4a5098e791f4e8a42db [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
Richard Smith1d209d02013-05-23 01:49:11 +00009// With modules
10// RUN: %clang_cc1 -fsyntax-only -verify -fmodules %s -chain-include %s -chain-include %s
11
Andy Gibbsc6e68da2012-10-19 12:44:48 +000012// expected-no-diagnostics
13
Andrew Trickba266ee2010-10-19 21:54:32 +000014#ifndef HEADER1
15#define HEADER1
16//===----------------------------------------------------------------------===//
17// Primary header for C++ chained PCH test
18
19void f();
20
21// Name not appearing in dependent
22void pf();
23
24namespace ns {
25 void g();
26
27 void pg();
28}
29
30template <typename T>
31struct S { typedef int G; };
32
33// Partially specialize
34template <typename T>
35struct S<T *> { typedef int H; };
36
Argyrios Kyrtzidisa41f6602010-10-20 00:11:15 +000037template <typename T> struct TS2;
38typedef TS2<int> TS2int;
39
Anders Carlsson1f13bb52011-03-09 05:09:32 +000040template <typename T> struct TestBaseSpecifiers { };
41template<typename T> struct TestBaseSpecifiers2 : TestBaseSpecifiers<T> { };
42
Sebastian Redl2ac2c722011-04-29 08:19:30 +000043template <typename T>
44struct TS3 {
45 static const int value = 0;
Richard Smithed2974f2011-12-21 00:25:33 +000046 static const int value2;
Sebastian Redl2ac2c722011-04-29 08:19:30 +000047};
48template <typename T>
49const int TS3<T>::value;
Richard Smithed2974f2011-12-21 00:25:33 +000050template <typename T>
51const int TS3<T>::value2 = 1;
Sebastian Redl2ac2c722011-04-29 08:19:30 +000052// Instantiate struct, but not value.
53struct instantiate : TS3<int> {};
54
Douglas Gregor05f10352011-12-17 23:38:30 +000055// Typedef
56typedef int Integer;
Sebastian Redl2ac2c722011-04-29 08:19:30 +000057
Andrew Trickba266ee2010-10-19 21:54:32 +000058//===----------------------------------------------------------------------===//
59#elif not defined(HEADER2)
60#define HEADER2
Sebastian Redl2ac2c722011-04-29 08:19:30 +000061#if !defined(HEADER1)
62#error Header inclusion order messed up
63#endif
64
Andrew Trickba266ee2010-10-19 21:54:32 +000065//===----------------------------------------------------------------------===//
66// Dependent header for C++ chained PCH test
67
68// Overload function from primary
69void f(int);
70
71// Add function with different name
72void f2();
73
74// Reopen namespace
75namespace ns {
76 // Overload function from primary
77 void g(int);
78
79 // Add different name
80 void g2();
81}
82
83// Specialize template from primary
84template <>
85struct S<int> { typedef int I; };
86
87// Partially specialize
88template <typename T>
89struct S<T &> { typedef int J; };
90
91// Specialize previous partial specialization
92template <>
93struct S<int *> { typedef int K; };
94
95// Specialize the partial specialization from this file
96template <>
97struct S<int &> { typedef int L; };
98
Argyrios Kyrtzidisa41f6602010-10-20 00:11:15 +000099template <typename T> struct TS2 { };
100
Anders Carlsson1f13bb52011-03-09 05:09:32 +0000101struct TestBaseSpecifiers3 { };
102struct TestBaseSpecifiers4 : TestBaseSpecifiers3 { };
103
Anders Carlsson9bb83e82011-03-06 18:41:18 +0000104struct A { };
105struct B : A { };
106
Richard Smithed2974f2011-12-21 00:25:33 +0000107// Instantiate TS3's members.
Sebastian Redl2ac2c722011-04-29 08:19:30 +0000108static const int ts3m1 = TS3<int>::value;
Richard Smithed2974f2011-12-21 00:25:33 +0000109extern int arr[TS3<int>::value2];
Sebastian Redl2ac2c722011-04-29 08:19:30 +0000110
Douglas Gregor05f10352011-12-17 23:38:30 +0000111// Redefinition of typedef
112typedef int Integer;
113
Andrew Trickba266ee2010-10-19 21:54:32 +0000114//===----------------------------------------------------------------------===//
115#else
116//===----------------------------------------------------------------------===//
117
Sebastian Redl9617e7e2010-08-24 00:50:16 +0000118void test() {
119 f();
120 f(1);
121 pf();
122 f2();
123
124 ns::g();
125 ns::g(1);
126 ns::pg();
127 ns::g2();
128
Sebastian Redl401b39a2010-08-24 22:50:24 +0000129 typedef S<double>::G T1;
130 typedef S<double *>::H T2;
131 typedef S<int>::I T3;
132 typedef S<double &>::J T4;
133 typedef S<int *>::K T5;
134 typedef S<int &>::L T6;
Argyrios Kyrtzidisa41f6602010-10-20 00:11:15 +0000135
136 TS2int ts2;
Anders Carlsson9bb83e82011-03-06 18:41:18 +0000137
138 B b;
Douglas Gregor05f10352011-12-17 23:38:30 +0000139 Integer i = 17;
Sebastian Redl9617e7e2010-08-24 00:50:16 +0000140}
Andrew Trickba266ee2010-10-19 21:54:32 +0000141
Sebastian Redl2ac2c722011-04-29 08:19:30 +0000142// Should have remembered that there is a definition.
143static const int ts3m2 = TS3<int>::value;
Richard Smithed2974f2011-12-21 00:25:33 +0000144int arr[TS3<int>::value2];
Sebastian Redl2ac2c722011-04-29 08:19:30 +0000145
Andrew Trickba266ee2010-10-19 21:54:32 +0000146//===----------------------------------------------------------------------===//
147#endif