DelayedTemplateParsing.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. // RUN: %clang_cc1 -fms-extensions -fdelayed-template-parsing -fsyntax-only -verify -std=c++11 %s
  2. template <class T>
  3. class A {
  4. void foo() {
  5. undeclared();
  6. }
  7. void foo2();
  8. };
  9. template <class T>
  10. class B {
  11. void foo4() { } // expected-note {{previous definition is here}}
  12. void foo4() { } // expected-error {{class member cannot be redeclared}}
  13. void foo5() { } // expected-note {{previous definition is here}}
  14. friend void foo3() {
  15. undeclared();
  16. }
  17. };
  18. template <class T>
  19. void B<T>::foo5() { // expected-error {{redefinition of 'foo5'}}
  20. }
  21. template <class T>
  22. void A<T>::foo2() {
  23. undeclared();
  24. }
  25. template <class T>
  26. void foo3() {
  27. undeclared();
  28. }
  29. template void A<int>::foo2();
  30. void undeclared()
  31. {
  32. }
  33. template <class T> void foo5() {} //expected-note {{previous definition is here}}
  34. template <class T> void foo5() {} // expected-error {{redefinition of 'foo5'}}
  35. namespace Inner_Outer_same_template_param_name {
  36. template <class T>
  37. class Outmost {
  38. public:
  39. template <class T>
  40. class Inner {
  41. public:
  42. void f() {
  43. T* var;
  44. }
  45. };
  46. };
  47. }
  48. namespace PR11931 {
  49. template <typename RunType>
  50. struct BindState;
  51. template<>
  52. struct BindState<void(void*)> {
  53. static void Run() { }
  54. };
  55. class Callback {
  56. public:
  57. typedef void RunType();
  58. template <typename RunType>
  59. Callback(BindState<RunType> bind_state) {
  60. BindState<RunType>::Run();
  61. }
  62. };
  63. Callback Bind() {
  64. return Callback(BindState<void(void*)>());
  65. }
  66. }
  67. namespace rdar11700604 {
  68. template<typename T> void foo() = delete;
  69. struct X {
  70. X() = default;
  71. template<typename T> void foo() = delete;
  72. };
  73. }
  74. namespace PR17334 {
  75. template <typename = void> struct ArrayRef {
  76. constexpr ArrayRef() {}
  77. };
  78. template <typename = void> void CreateConstInBoundsGEP2_32() {
  79. ArrayRef<> IdxList;
  80. }
  81. void LLVMBuildStructGEP() { CreateConstInBoundsGEP2_32(); }
  82. }
  83. namespace PR17661 {
  84. template <typename T>
  85. constexpr T Fun(T A) { return T(0); }
  86. constexpr int Var = Fun(20);
  87. }
  88. template <typename T>
  89. auto invalidTrailingRetType() -> Bogus {} // expected-error {{unknown type name 'Bogus'}}
  90. namespace PR19613 {
  91. struct HeapTypeConfig {
  92. static void from_bitset();
  93. };
  94. template <class Config>
  95. struct TypeImpl {
  96. struct BitsetType;
  97. static void Any() {
  98. BitsetType::New();
  99. }
  100. };
  101. template<class Config>
  102. struct TypeImpl<Config>::BitsetType {
  103. static void New() {
  104. Config::from_bitset();
  105. }
  106. };
  107. static void f() {
  108. TypeImpl<HeapTypeConfig>::Any();
  109. }
  110. template<typename A> struct S {
  111. template<typename B> struct T;
  112. };
  113. template<typename A> template<typename B> struct S<A>::T {
  114. template<typename C, typename D> struct U;
  115. template<typename C> struct U<C, C> {
  116. template<typename E> static int f() {
  117. return sizeof(A) + sizeof(B) + sizeof(C) + sizeof(E);
  118. }
  119. };
  120. };
  121. static void g() {
  122. S<int>::T<int>::U<int,int>::f<int>();
  123. }
  124. template<typename T> struct SS {
  125. template<typename U> struct X;
  126. template<typename U> struct X<U*>;
  127. };
  128. template<typename T> template<typename U> struct SS<T>::X<U*> {
  129. static int f() {
  130. return sizeof(T) + sizeof(U);
  131. }
  132. };
  133. static void h() {
  134. SS<int>::X<int*>::f();
  135. }
  136. }