cxx-ambig-init-templ.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. // RUN: %clang_cc1 -Wno-uninitialized -std=c++11 -verify %s
  2. template<int> struct c { c(int) = delete; typedef void val; operator int() const; };
  3. int val;
  4. int foobar;
  5. struct S {
  6. int k1 = a < b < c, d > ::val, e1;
  7. int k2 = a < b, c < d > ::val, e2;
  8. int k3 = b < a < c, d > ::val, e3;
  9. int k4 = b < c, x, y = d > ::val, e4;
  10. int k5 = T1 < b, &S::operator=(int); // expected-error {{extra qualification}}
  11. int k6 = T2 < b, &S::operator= >::val;
  12. int k7 = T1 < b, &S::operator>(int); // expected-error {{extra qualification}}
  13. int k8 = T2 < b, &S::operator> >::val;
  14. int k9 = T3 < a < b, c >> (d), e5 = 1 > (e4);
  15. int k10 = 0 < T3 < a < b, c >> (d
  16. ) // expected-error {{expected ';' at end of declaration}}
  17. , a > (e4);
  18. int k11 = 0 < 1, c<3>::*ptr;
  19. int k12 = e < 0, int a<b<c>::* >(), e11;
  20. void f1(
  21. int k1 = a < b < c, d > ::val,
  22. int k2 = b < a < c, d > ::val,
  23. int k3 = b < c, int x = 0 > ::val,
  24. int k4 = a < b, T3 < int > >(), // expected-error {{must be an expression}}
  25. int k5 = a < b, c < d > ::val,
  26. int k6 = a < b, c < d > (n) // expected-error {{undeclared identifier 'n'}}
  27. );
  28. void f2a(
  29. // T3<int> here is a parameter type, so must be declared before it is used.
  30. int k1 = c < b, T3 < int > x = 0 // expected-error {{unexpected end of default argument expression}}
  31. );
  32. template<typename, int=0> struct T3 { T3(int); operator int(); };
  33. void f2b(
  34. int k1 = c < b, T3 < int > x = 0 // ok
  35. );
  36. // This is a one-parameter function. Ensure we don't typo-correct it to
  37. // int = a < b, c < foobar > ()
  38. // ... which would be a function with two parameters.
  39. int f3(int = a < b, c < goobar > ());
  40. static constexpr int (S::*f3_test)(int) = &S::f3;
  41. void f4(
  42. int k1 = a<1,2>::val,
  43. int missing_default // expected-error {{missing default argument on parameter}}
  44. );
  45. void f5(
  46. int k1 = b < c,
  47. int missing_default // expected-error {{missing default argument on parameter}}
  48. );
  49. void f6(
  50. int k = b < c,
  51. unsigned int (missing_default) // expected-error {{missing default argument on parameter}}
  52. );
  53. template<int, int=0> struct a { static const int val = 0; operator int(); }; // expected-note {{here}}
  54. static const int b = 0, c = 1, d = 2, goobar = 3;
  55. template<int, typename> struct e { operator int(); };
  56. int mp1 = 0 < 1,
  57. a<b<c,b<c>::*mp2,
  58. mp3 = 0 > a<b<c>::val,
  59. a<b<c,b<c>::*mp4 = 0,
  60. a<b<c,b<c>::*mp5 {0},
  61. a<b<c,b<c>::*mp6;
  62. int np1 = e<0, int a<b<c,b<c>::*>();
  63. static const int T1 = 4;
  64. template<int, int &(S::*)(int)> struct T2 { static const int val = 0; };
  65. };
  66. namespace NoAnnotationTokens {
  67. template<bool> struct Bool { Bool(int); };
  68. static const bool in_class = false;
  69. struct Test {
  70. // Check we don't keep around a Bool<false> annotation token here.
  71. int f(Bool<true> = X<Y, Bool<in_class> >(0));
  72. // But it's OK if we do here.
  73. int g(Bool<true> = Z<Y, Bool<in_class> = Bool<false>(0));
  74. static const bool in_class = true;
  75. template<int, typename U> using X = U;
  76. static const int Y = 0, Z = 0;
  77. };
  78. }
  79. namespace ImplicitInstantiation {
  80. template<typename T> struct HasError { typename T::error error; }; // expected-error {{has no members}}
  81. struct S {
  82. // This triggers the instantiation of the outer HasError<int> during
  83. // disambiguation, even though it uses the inner HasError<int>.
  84. void f(int a = X<Y, HasError<int>::Z >()); // expected-note {{in instantiation of}}
  85. template<typename, typename> struct X { operator int(); };
  86. typedef int Y;
  87. template<typename> struct HasError { typedef int Z; };
  88. };
  89. HasError<int> hei;
  90. }
  91. namespace CWG325 {
  92. template <int A, typename B> struct T { static int i; operator int(); };
  93. class C {
  94. int Foo (int i = T<1, int>::i);
  95. };
  96. class D {
  97. int Foo (int i = T<1, int>::i);
  98. template <int A, typename B> struct T {static int i;};
  99. };
  100. const int a = 0;
  101. typedef int b;
  102. T<a,b> c;
  103. struct E {
  104. int n = T<a,b>(c);
  105. };
  106. }
  107. namespace Operators {
  108. struct Y {};
  109. constexpr int operator,(const Y&, const Y&) { return 8; }
  110. constexpr int operator>(const Y&, const Y&) { return 8; }
  111. constexpr int operator<(const Y&, const Y&) { return 8; }
  112. constexpr int operator>>(const Y&, const Y&) { return 8; }
  113. struct X {
  114. typedef int (*Fn)(const Y&, const Y&);
  115. Fn a = operator,, b = operator<, c = operator>;
  116. void f(Fn a = operator,, Fn b = operator<, Fn c = operator>);
  117. int k1 = T1<0, operator<, operator>, operator<>::val, l1;
  118. int k2 = T1<0, operator>, operator,, operator,>::val, l2;
  119. int k3 = T2<0, operator,(Y{}, Y{}), operator<(Y{}, Y{})>::val, l3;
  120. int k4 = T2<0, operator>(Y{}, Y{}), operator,(Y{}, Y{})>::val, l4;
  121. int k5 = T3<0, operator>>>::val, l5;
  122. int k6 = T4<0, T3<0, operator>>>>::val, l6;
  123. template<int, Fn, Fn, Fn> struct T1 { enum { val }; };
  124. template<int, int, int> struct T2 { enum { val }; };
  125. template<int, Fn> struct T3 { enum { val }; };
  126. template<int, typename T> struct T4 : T {};
  127. };
  128. }
  129. namespace ElaboratedTypeSpecifiers {
  130. struct S {
  131. int f(int x = T<a, struct S>());
  132. int h(int x = T<a, union __attribute__(()) U>());
  133. int i(int x = T<a, enum E>());
  134. int j(int x = T<a, struct S::template T<0, enum E>>());
  135. template <int, typename> struct T { operator int(); };
  136. static const int a = 0;
  137. enum E {};
  138. };
  139. }
  140. namespace PR20459 {
  141. template <typename EncTraits> struct A {
  142. void foo(int = EncTraits::template TypeEnc<int, int>::val); // ok
  143. };
  144. }