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