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