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 #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 };
     42 template <typename T>
     43 const int TS3<T>::value;
     44 // Instantiate struct, but not value.
     45 struct instantiate : TS3<int> {};
     46 
     47 
     48 //===----------------------------------------------------------------------===//
     49 #elif not defined(HEADER2)
     50 #define HEADER2
     51 #if !defined(HEADER1)
     52 #error Header inclusion order messed up
     53 #endif
     54 
     55 //===----------------------------------------------------------------------===//
     56 // Dependent header for C++ chained PCH test
     57 
     58 // Overload function from primary
     59 void f(int);
     60 
     61 // Add function with different name
     62 void f2();
     63 
     64 // Reopen namespace
     65 namespace ns {
     66   // Overload function from primary
     67   void g(int);
     68 
     69   // Add different name
     70   void g2();
     71 }
     72 
     73 // Specialize template from primary
     74 template <>
     75 struct S<int> { typedef int I; };
     76 
     77 // Partially specialize
     78 template <typename T>
     79 struct S<T &> { typedef int J; };
     80 
     81 // Specialize previous partial specialization
     82 template <>
     83 struct S<int *> { typedef int K; };
     84 
     85 // Specialize the partial specialization from this file
     86 template <>
     87 struct S<int &> { typedef int L; };
     88 
     89 template <typename T> struct TS2 { };
     90 
     91 struct TestBaseSpecifiers3 { };
     92 struct TestBaseSpecifiers4 : TestBaseSpecifiers3 { };
     93 
     94 struct A { };
     95 struct B : A { };
     96 
     97 // Instantiate TS3's member.
     98 static const int ts3m1 = TS3<int>::value;
     99 
    100 //===----------------------------------------------------------------------===//
    101 #else
    102 //===----------------------------------------------------------------------===//
    103 
    104 void test() {
    105   f();
    106   f(1);
    107   pf();
    108   f2();
    109 
    110   ns::g();
    111   ns::g(1);
    112   ns::pg();
    113   ns::g2();
    114 
    115   typedef S<double>::G T1;
    116   typedef S<double *>::H T2;
    117   typedef S<int>::I T3;
    118   typedef S<double &>::J T4;
    119   typedef S<int *>::K T5;
    120   typedef S<int &>::L T6;
    121 
    122   TS2int ts2;
    123 
    124   B b;
    125 }
    126 
    127 // Should have remembered that there is a definition.
    128 static const int ts3m2 = TS3<int>::value;
    129 
    130 //===----------------------------------------------------------------------===//
    131 #endif
    132