Home | History | Annotate | Download | only in PCH
      1 // Test this without pch.
      2 // RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -include %S/cxx-templates.h -verify %s -ast-dump -o -
      3 // RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -include %S/cxx-templates.h %s -emit-llvm -o - | FileCheck %s
      4 
      5 // Test with pch.
      6 // RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -x c++-header -emit-pch -o %t %S/cxx-templates.h
      7 // RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -include-pch %t -verify %s -ast-dump  -o -
      8 // RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -include-pch %t %s -emit-llvm -o - -error-on-deserialized-decl doNotDeserialize | FileCheck %s
      9 
     10 // Test with modules.
     11 // RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -fmodules -x c++-header -emit-pch -o %t %S/cxx-templates.h
     12 // RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -fmodules -include-pch %t -verify %s -ast-dump  -o -
     13 // RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -fexceptions -fmodules -include-pch %t %s -emit-llvm -o - -error-on-deserialized-decl doNotDeserialize | FileCheck %s
     14 
     15 // expected-no-diagnostics
     16 
     17 // CHECK: define weak_odr void @_ZN2S4IiE1mEv
     18 // CHECK: define linkonce_odr void @_ZN2S3IiE1mEv
     19 
     20 struct A {
     21   typedef int type;
     22   static void my_f();
     23   template <typename T>
     24   static T my_templf(T x) { return x; }
     25 };
     26 
     27 void test(const int (&a6)[17]) {
     28   int x = templ_f<int, 5>(3);
     29 
     30   S<char, float>::templ();
     31   S<int, char>::partial();
     32   S<int, float>::explicit_special();
     33 
     34   Dep<A>::Ty ty;
     35   Dep<A> a;
     36   a.f();
     37 
     38   S3<int> s3;
     39   s3.m();
     40 
     41   TS5 ts(0);
     42 
     43   S6<const int[17]>::t2 b6 = a6;
     44 }
     45 
     46 template struct S4<int>;
     47 
     48 S7<int[5]> s7_5;
     49 
     50 namespace ZeroLengthExplicitTemplateArgs {
     51   template void f<X>(X*);
     52 }
     53 
     54 // This used to overwrite memory and crash.
     55 namespace Test1 {
     56   struct StringHasher {
     57     template<typename T, char Converter(T)> static inline unsigned createHash(const T*, unsigned) {
     58       return 0;
     59     }
     60   };
     61 
     62   struct CaseFoldingHash {
     63     static inline char foldCase(char) {
     64       return 0;
     65     }
     66 
     67     static unsigned hash(const char* data, unsigned length) {
     68       return StringHasher::createHash<char, foldCase>(data, length);
     69     }
     70   };
     71 }
     72 
     73 template< typename D >
     74 Foo< D >& Foo< D >::operator=( const Foo& other )
     75 {
     76    return *this;
     77 }
     78 
     79 namespace TestNestedExpansion {
     80   struct Int {
     81     Int(int);
     82     friend Int operator+(Int, Int);
     83   };
     84   Int &g(Int, int, double);
     85   Int &test = NestedExpansion<char, char, char>().f(0, 1, 2, Int(3), 4, 5.0);
     86 }
     87 
     88 namespace rdar13135282 {
     89   void test() {
     90     __mt_alloc<> mt = __mt_alloc<>();
     91   }
     92 }
     93 
     94 void CallDependentSpecializedFunc(DependentSpecializedFuncClass<int> &x) {
     95   DependentSpecializedFunc(x);
     96 }
     97 
     98 namespace cyclic_module_load {
     99   extern std::valarray<int> x;
    100   std::valarray<int> y(x);
    101 }
    102