cxx-templates.cpp 3.7 KB

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