brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.4 KiB · 11ad401 Raw
189 lines · cpp
1// Test this without pch.2// RUN: %clang_cc1 -std=c++17 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -include %S/cxx-templates.h -verify %s3// RUN: %clang_cc1 -std=c++17 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -include %S/cxx-templates.h %s -emit-llvm -o - -DNO_ERRORS | FileCheck %s4 5// Test with pch.6// RUN: %clang_cc1 -std=c++17 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -x c++-header -emit-pch -o %t %S/cxx-templates.h7// RUN: %clang_cc1 -std=c++17 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -include-pch %t -verify %s8// RUN: %clang_cc1 -std=c++17 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -include-pch %t %s -emit-llvm -o - -error-on-deserialized-decl doNotDeserialize -DNO_ERRORS | FileCheck %s9 10// Test with modules.11// RUN: %clang_cc1 -std=c++17 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -fmodules -x c++-header -emit-pch -o %t %S/cxx-templates.h12// RUN: %clang_cc1 -std=c++17 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -fmodules -include-pch %t -verify %s13// RUN: %clang_cc1 -std=c++17 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -fmodules -include-pch %t %s -emit-llvm -o - -error-on-deserialized-decl doNotDeserialize -DNO_ERRORS -fmodules-ignore-macro=NO_ERRORS | FileCheck %s14 15// Test with pch and delayed template parsing.16// RUN: %clang_cc1 -std=c++17 -triple %itanium_abi_triple -fcxx-exceptions -fdelayed-template-parsing -fexceptions -x c++-header -emit-pch -o %t %S/cxx-templates.h17// RUN: %clang_cc1 -std=c++17 -triple %itanium_abi_triple -fcxx-exceptions -fdelayed-template-parsing -fexceptions -include-pch %t -verify %s18// RUN: %clang_cc1 -std=c++17 -triple %itanium_abi_triple -fcxx-exceptions -fdelayed-template-parsing -fexceptions -include-pch %t %s -emit-llvm -o - -DNO_ERRORS | FileCheck %s19 20// Test with pch and template instantiation in the pch.21// RUN: %clang_cc1 -std=c++17 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -fpch-instantiate-templates -x c++-header -emit-pch -o %t %S/cxx-templates.h22// RUN: %clang_cc1 -std=c++17 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -include-pch %t -verify %s23// RUN: %clang_cc1 -std=c++17 -triple %itanium_abi_triple -fcxx-exceptions -fexceptions -include-pch %t %s -emit-llvm -o - -DNO_ERRORS | FileCheck %s24 25// CHECK: define weak_odr {{.*}}void @_ZN2S4IiE1mEv26// CHECK: define linkonce_odr {{.*}}void @_ZN2S3IiE1mEv27 28struct A {29  typedef int type;30  static void my_f();31  template <typename T>32  static T my_templf(T x) { return x; }33};34 35void test(const int (&a6)[17]) {36  int x = templ_f<int, 5>(3);37  38  S<char, float>::templ();39  S<int, char>::partial();40  S<int, float>::explicit_special();41  42  Dep<A>::Ty ty;43  Dep<A> a;44  a.f();45  46  S3<int> s3;47  s3.m();48 49  TS5 ts(0);50 51  S6<const int[17]>::t2 b6 = a6;52}53 54template struct S4<int>;55 56S7<int[5]> s7_5;57 58namespace ZeroLengthExplicitTemplateArgs {59  template void f<X>(X*);60}61 62// This used to overwrite memory and crash.63namespace Test1 {64  struct StringHasher {65    template<typename T, char Converter(T)> static inline unsigned createHash(const T*, unsigned) {66      return 0;67    }68  };69 70  struct CaseFoldingHash {71    static inline char foldCase(char) {72      return 0;73    }74 75    static unsigned hash(const char* data, unsigned length) {76      return StringHasher::createHash<char, foldCase>(data, length);77    }78  };79}80 81template< typename D >82Foo< D >& Foo< D >::operator=( const Foo& other )83{84   return *this;85}86 87namespace TestNestedExpansion {88  struct Int {89    Int(int);90    friend Int operator+(Int, Int);91  };92  Int &g(Int, int, double);93  Int &test = NestedExpansion<char, char, char>().f(0, 1, 2, Int(3), 4, 5.0);94}95 96namespace rdar13135282 {97  void test() {98    __mt_alloc<> mt = __mt_alloc<>();99  }100}101 102void CallDependentSpecializedFunc(DependentSpecializedFuncClass<int> &x) {103  DependentSpecializedFunc(x);104}105 106namespace cyclic_module_load {107  extern std::valarray<int> x;108  std::valarray<int> y(x);109}110 111#ifndef NO_ERRORS112// expected-error@cxx-templates.h:304 {{incomplete}}113template int local_extern::f<int[]>(); // expected-note {{in instantiation of}}114#endif115template int local_extern::g<int[]>();116 117namespace MemberSpecializationLocation {118#ifndef NO_ERRORS119  // expected-note@cxx-templates.h:* {{previous}}120  template<> float A<int>::n; // expected-error {{redeclaration of 'n' with a different type}}121#endif122  int k = A<int>::n;123}124 125// https://bugs.llvm.org/show_bug.cgi?id=34728126namespace PR34728 {127int test() {128  // Verify with several TemplateParmDecl kinds, using PCH (incl. modules).129  int z1 = func1(/*ignored*/2.718);130  int z2 = func2(/*ignored*/3.142);131  int tmp3 = 30;132  Container<int> c = func3(tmp3);133  int z3 = c.item;134 135  // Return value is meaningless.  Just "use" all these values to avoid136  // warning about unused vars / values.137  return z1 + z2 + z3;138}139} // end namespace PR34728140 141namespace ClassScopeExplicitSpecializations {142  // FIXME: It's unclear these warnings (and the behavior they're describing)143  // are desirable. These explicit instantiations could meaningfully144  // instantiate the explicit specializations defined in the primary template.145  template int A<3>::f<0>() const; // expected-warning {{has no effect}}146  template int A<3>::f<1>() const;147  template int A<4>::f<0>() const; // expected-warning {{has no effect}}148  template int A<4>::f<1>() const;149  // expected-note@cxx-templates.h:402 2{{here}}150 151  static_assert(A<0>().f<0>() == 4, "");152  static_assert(A<0>().f<1>() == 5, "");153  static_assert(A<0>().f<2>() == 3, "");154  static_assert(A<1>().f<0>() == 2, "");155  static_assert(A<1>().f<1>() == 1, "");156  static_assert(A<1>().f<2>() == 1, "");157  static_assert(A<2>().f<0>() == 2, "");158  static_assert(A<2>().f<1>() == 1, "");159  static_assert(A<3>().f<0>() == 2, "");160  static_assert(A<3>().f<1>() == 1, "");161  static_assert(A<4>().f<0>() == 2, "");162  static_assert(A<4>().f<1>() == 1, "");163}164 165namespace DependentMemberExpr {166#ifndef NO_ERRORS167  // This used to mark 'f' invalid without producing any diagnostic. That's a168  // little hard to detect, but we can make sure that constexpr evaluation169  // fails when it should.170  static_assert(A<int>().f() == 1); // expected-error {{static assertion failed}} \171                                    // expected-note {{evaluates to '0 == 1'}}172#endif173}174 175namespace DependentTemplateName {176  struct HasMember {177    template <class T> struct Member;178  };179 180  void test() {181    getWithIdentifier<HasMember>();182  }183}184 185namespace ClassTemplateCycle {186  extern T t;187  int k = M;188}189