nested-name-spec-template.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. namespace N {
  3. namespace M {
  4. template<typename T> struct Promote;
  5. template<> struct Promote<short> {
  6. typedef int type;
  7. };
  8. template<> struct Promote<int> {
  9. typedef int type;
  10. };
  11. template<> struct Promote<float> {
  12. typedef double type;
  13. };
  14. Promote<short>::type *ret_intptr(int* ip) { return ip; }
  15. Promote<int>::type *ret_intptr2(int* ip) { return ip; }
  16. }
  17. M::Promote<int>::type *ret_intptr3(int* ip) { return ip; }
  18. M::template Promote<int>::type *ret_intptr4(int* ip) { return ip; } // expected-warning{{'template' keyword outside of a template}}
  19. M::template Promote<int> pi; // expected-warning{{'template' keyword outside of a template}}
  20. }
  21. N::M::Promote<int>::type *ret_intptr5(int* ip) { return ip; }
  22. ::N::M::Promote<int>::type *ret_intptr6(int* ip) { return ip; }
  23. N::M::template; // expected-error{{expected unqualified-id}}
  24. N::M::template Promote; // expected-error{{expected unqualified-id}}
  25. namespace N {
  26. template<typename T> struct A;
  27. template<>
  28. struct A<int> {
  29. struct X;
  30. };
  31. struct B;
  32. }
  33. struct ::N::A<int>::X {
  34. int foo;
  35. };
  36. template<typename T>
  37. struct TestA {
  38. typedef typename N::template B<T>::type type; // expected-error{{'B' following the 'template' keyword does not refer to a template}} \
  39. // expected-error{{expected member name}}
  40. };
  41. // Reduced from a Boost failure.
  42. namespace test1 {
  43. template <class T> struct pair {
  44. T x;
  45. T y;
  46. static T pair<T>::* const mem_array[2];
  47. };
  48. template <class T>
  49. T pair<T>::* const pair<T>::mem_array[2] = { &pair<T>::x, &pair<T>::y };
  50. }
  51. typedef int T;
  52. namespace N1 {
  53. template<typename T> T f0();
  54. }
  55. template<typename T> T N1::f0() { }
  56. namespace PR7385 {
  57. template< typename > struct has_xxx0
  58. {
  59. template< typename > struct has_xxx0_introspect
  60. {
  61. template< typename > struct has_xxx0_substitute ;
  62. template< typename V >
  63. int int00( has_xxx0_substitute < typename V::template xxx< > > = 0 );
  64. };
  65. static const int value = has_xxx0_introspect<int>::value; // expected-error{{no member named 'value'}}
  66. typedef int type;
  67. };
  68. has_xxx0<int>::type t; // expected-note{{instantiation of}}
  69. }
  70. namespace PR7725 {
  71. template<class ignored> struct TypedefProvider;
  72. template<typename T>
  73. struct TemplateClass : public TypedefProvider<T>
  74. {
  75. void PrintSelf() {
  76. TemplateClass::Test::PrintSelf();
  77. }
  78. };
  79. }
  80. namespace PR9226 {
  81. template<typename a>
  82. void nt() // expected-note{{function template 'nt' declared here}}
  83. { nt<>:: } // expected-error{{qualified name refers into a specialization of function template 'nt'}} \
  84. // expected-error{{expected unqualified-id}}
  85. template<typename T>
  86. void f(T*); // expected-note{{function template 'f' declared here}}
  87. template<typename T>
  88. void f(T*, T*); // expected-note{{function template 'f' declared here}}
  89. void g() {
  90. f<int>:: // expected-error{{qualified name refers into a specialization of function template 'f'}}
  91. } // expected-error{{expected unqualified-id}}
  92. struct X {
  93. template<typename T> void f(); // expected-note{{function template 'f' declared here}}
  94. };
  95. template<typename T, typename U>
  96. struct Y {
  97. typedef typename T::template f<U> type; // expected-error{{template name refers to non-type template 'X::f'}}
  98. };
  99. Y<X, int> yxi; // expected-note{{in instantiation of template class 'PR9226::Y<PR9226::X, int>' requested here}}
  100. }
  101. namespace PR9449 {
  102. template <typename T>
  103. struct s; // expected-note{{template is declared here}}
  104. template <typename T>
  105. void f() {
  106. int s<T>::template n<T>::* f; // expected-error{{implicit instantiation of undefined template 'PR9449::s<int>'}} \
  107. // expected-error{{following the 'template' keyword}}
  108. }
  109. template void f<int>(); // expected-note{{in instantiation of}}
  110. }