nested-template.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. class A;
  3. class S {
  4. public:
  5. template<typename T> struct A {
  6. struct Nested {
  7. typedef T type;
  8. };
  9. };
  10. };
  11. int i;
  12. S::A<int>::Nested::type *ip = &i;
  13. template<typename T>
  14. struct Outer {
  15. template<typename U>
  16. class Inner0;
  17. template<typename U>
  18. class Inner1 {
  19. struct ReallyInner;
  20. T foo(U);
  21. template<typename V> T bar(V);
  22. template<typename V> T* bar(V);
  23. static T value1;
  24. static U value2;
  25. };
  26. };
  27. template<typename X>
  28. template<typename Y>
  29. class Outer<X>::Inner0 {
  30. public:
  31. void f(X, Y);
  32. };
  33. template<typename X>
  34. template<typename Y>
  35. void Outer<X>::Inner0<Y>::f(X, Y) {
  36. }
  37. template<typename X>
  38. template<typename Y>
  39. struct Outer<X>::Inner1<Y>::ReallyInner {
  40. static Y value3;
  41. void g(X, Y);
  42. };
  43. template<typename X>
  44. template<typename Y>
  45. void Outer<X>::Inner1<Y>::ReallyInner::g(X, Y) {
  46. }
  47. template<typename X>
  48. template<typename Y>
  49. X Outer<X>::Inner1<Y>::foo(Y) {
  50. return X();
  51. }
  52. template<typename X>
  53. template<typename Y>
  54. template<typename Z>
  55. X Outer<X>::Inner1<Y>::bar(Z) {
  56. return X();
  57. }
  58. template<typename X>
  59. template<typename Y>
  60. template<typename Z>
  61. X* Outer<X>::Inner1<Y>::bar(Z) {
  62. return 0;
  63. }
  64. template<typename X>
  65. template<typename Y>
  66. X Outer<X>::Inner1<Y>::value1 = 0;
  67. template<typename X>
  68. template<typename Y>
  69. Y Outer<X>::Inner1<Y>::value2 = Y();
  70. template<typename X>
  71. template<typename Y>
  72. Y Outer<X>::Inner1<Y>::ReallyInner::value3 = Y();
  73. template<typename X>
  74. template<typename Y>
  75. Y Outer<X>::Inner1<Y*>::ReallyInner::value4; // expected-error{{Outer<X>::Inner1<Y *>::ReallyInner::}}
  76. template<typename T>
  77. struct X0 { };
  78. template<typename T>
  79. struct X0<T*> {
  80. template<typename U>
  81. void f(U u = T()) { }
  82. };
  83. // PR5103
  84. template<typename>
  85. struct X1 {
  86. template<typename, bool = false> struct B { };
  87. };
  88. template struct X1<int>::B<bool>;
  89. // Template template parameters
  90. template<typename T>
  91. struct X2 {
  92. template<template<class U, T Value> class> // expected-error{{cannot have type 'float'}} \
  93. // expected-note{{previous non-type template}}
  94. struct Inner { };
  95. };
  96. template<typename T,
  97. int Value> // expected-note{{template non-type parameter}}
  98. struct X2_arg;
  99. X2<int>::Inner<X2_arg> x2i1;
  100. X2<float> x2a; // expected-note{{instantiation}}
  101. X2<long>::Inner<X2_arg> x2i3; // expected-error{{template template argument has different}}
  102. namespace PR10896 {
  103. template<typename TN>
  104. class Foo {
  105. public:
  106. void foo() {}
  107. private:
  108. template<typename T>
  109. T SomeField; // expected-error {{member 'SomeField' declared as a template}}
  110. template<> int SomeField2; // expected-error {{extraneous 'template<>' in declaration of member 'SomeField2'}}
  111. };
  112. void g() {
  113. Foo<int> f;
  114. f.foo();
  115. }
  116. }
  117. namespace PR10924 {
  118. template< class Topology, class ctype >
  119. struct ReferenceElement
  120. {
  121. };
  122. template< class Topology, class ctype >
  123. template< int codim >
  124. class ReferenceElement< Topology, ctype > :: BaryCenterArray // expected-error{{out-of-line definition of 'BaryCenterArray' does not match any declaration in 'ReferenceElement<Topology, ctype>'}}
  125. {
  126. };
  127. }
  128. class Outer1 {
  129. template <typename T> struct X;
  130. template <typename T> int X<T>::func() {} // expected-error{{out-of-line definition of 'func' from class 'X<T>' without definition}}
  131. };