cxx-template-argument.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. // RUN: %clang_cc1 -fsyntax-only -verify %s -fdelayed-template-parsing
  3. template<typename T> struct A {};
  4. // Check for template argument lists followed by junk
  5. // FIXME: The diagnostics here aren't great...
  6. A<int+> int x; // expected-error {{expected '>'}} expected-error {{expected unqualified-id}}
  7. A<int x; // expected-error {{type-id cannot have a name}} expected-error {{expected '>'}}
  8. // PR8912
  9. template <bool> struct S {};
  10. S<bool(2 > 1)> s;
  11. // Test behavior when a template-id is ended by a token which starts with '>'.
  12. namespace greatergreater {
  13. template<typename T> struct S { S(); S(T); };
  14. void f(S<int>=0); // expected-error {{a space is required between a right angle bracket and an equals sign (use '> =')}}
  15. void f(S<S<int>>=S<int>()); // expected-error {{use '> >'}} expected-error {{use '> ='}}
  16. template<typename T> void t();
  17. void g() {
  18. void (*p)() = &t<int>;
  19. (void)(&t<int>==p); // expected-error {{use '> ='}}
  20. (void)(&t<int>>=p); // expected-error {{use '> >'}}
  21. (void)(&t<S<int>>>=p); // expected-error {{use '> >'}}
  22. (void)(&t<S<int>>==p); // expected-error {{use '> >'}} expected-error {{use '> ='}}
  23. }
  24. }
  25. namespace PR5925 {
  26. template <typename x>
  27. class foo { // expected-note {{here}}
  28. };
  29. void bar(foo *X) { // expected-error {{requires template arguments}}
  30. }
  31. }
  32. namespace PR13210 {
  33. template <class T>
  34. class C {}; // expected-note {{here}}
  35. void f() {
  36. new C(); // expected-error {{requires template arguments}}
  37. }
  38. }
  39. // Don't emit spurious messages
  40. namespace pr16225add {
  41. template<class T1, typename T2> struct Known { }; // expected-note 3 {{template is declared here}}
  42. template<class T1, typename T2> struct X;
  43. template<class T1, typename T2> struct ABC; // expected-note {{template is declared here}}
  44. template<int N1, int N2> struct ABC2 {};
  45. template<class T1, typename T2> struct foo :
  46. UnknownBase<T1,T2> // expected-error {{unknown template name 'UnknownBase'}}
  47. { };
  48. template<class T1, typename T2> struct foo2 :
  49. UnknownBase<T1,T2>, // expected-error {{unknown template name 'UnknownBase'}}
  50. Known<T1> // expected-error {{too few template arguments for class template 'Known'}}
  51. { };
  52. template<class T1, typename T2> struct foo3 :
  53. UnknownBase<T1,T2,ABC<T2,T1> > // expected-error {{unknown template name 'UnknownBase'}}
  54. { };
  55. template<class T1, typename T2> struct foo4 :
  56. UnknownBase<T1,ABC<T2> >, // expected-error {{unknown template name 'UnknownBase'}} \
  57. // expected-error {{too few template arguments for class template 'ABC'}}
  58. Known<T1> // expected-error {{too few template arguments for class template 'Known'}}
  59. { };
  60. template<class T1, typename T2> struct foo5 :
  61. UnknownBase<T1,T2,ABC<T2,T1>> // expected-error {{unknown template name 'UnknownBase'}} \
  62. // expected-error {{use '> >'}}
  63. { };
  64. template<class T1, typename T2> struct foo6 :
  65. UnknownBase<T1,ABC<T2,T1>>, // expected-error {{unknown template name 'UnknownBase'}} \
  66. // expected-error {{use '> >'}}
  67. Known<T1> // expected-error {{too few template arguments for class template 'Known'}}
  68. { };
  69. template<class T1, typename T2, int N> struct foo7 :
  70. UnknownBase<T1,T2,(N>1)> // expected-error {{unknown template name 'UnknownBase'}}
  71. { };
  72. template<class T1, typename T2> struct foo8 :
  73. UnknownBase<X<int,int>,X<int,int>> // expected-error {{unknown template name 'UnknownBase'}} \
  74. // expected-error {{use '> >'}}
  75. { };
  76. template<class T1, typename T2> struct foo9 :
  77. UnknownBase<Known<int,int>,X<int,int>> // expected-error {{unknown template name 'UnknownBase'}} \
  78. // expected-error {{use '> >'}}
  79. { };
  80. template<class T1, typename T2> struct foo10 :
  81. UnknownBase<Known<int,int>,X<int,X<int,int>>> // expected-error {{unknown template name 'UnknownBase'}} \
  82. // expected-error {{use '> >'}}
  83. { };
  84. template<int N1, int N2> struct foo11 :
  85. UnknownBase<2<N1,N2<4> // expected-error {{unknown template name 'UnknownBase'}}
  86. { };
  87. }
  88. namespace PR18793 {
  89. template<typename T, T> struct S {};
  90. template<typename T> int g(S<T, (T())> *);
  91. }