instantiate-expr-3.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. // ---------------------------------------------------------------------
  3. // Imaginary literals
  4. // ---------------------------------------------------------------------
  5. template<typename T>
  6. struct ImaginaryLiteral0 {
  7. void f(T &x) {
  8. x = 3.0I; // expected-error{{incompatible type}}
  9. }
  10. };
  11. template struct ImaginaryLiteral0<_Complex float>;
  12. template struct ImaginaryLiteral0<int*>; // expected-note{{instantiation}}
  13. // ---------------------------------------------------------------------
  14. // Compound assignment operator
  15. // ---------------------------------------------------------------------
  16. namespace N1 {
  17. struct X { };
  18. int& operator+=(X&, int); // expected-note{{candidate}}
  19. }
  20. namespace N2 {
  21. long& operator+=(N1::X&, long); // expected-note{{candidate}}
  22. template<typename T, typename U, typename Result>
  23. struct PlusEquals0 {
  24. void f(T t, U u) {
  25. Result r = t += u; // expected-error{{ambiguous}}
  26. }
  27. };
  28. }
  29. namespace N3 {
  30. struct Y : public N1::X {
  31. short& operator+=(long); // expected-note{{candidate}}
  32. };
  33. }
  34. template struct N2::PlusEquals0<N1::X, int, int&>;
  35. template struct N2::PlusEquals0<N1::X, long, long&>;
  36. template struct N2::PlusEquals0<N3::Y, long, short&>;
  37. template struct N2::PlusEquals0<int, int, int&>;
  38. template struct N2::PlusEquals0<N3::Y, int, short&>; // expected-note{{instantiation}}
  39. // ---------------------------------------------------------------------
  40. // Conditional operator
  41. // ---------------------------------------------------------------------
  42. template<typename T, typename U, typename Result>
  43. struct Conditional0 {
  44. void f(T t, U u) {
  45. Result result = t? : u;
  46. }
  47. };
  48. template struct Conditional0<int, int, int>;
  49. // ---------------------------------------------------------------------
  50. // Statement expressions
  51. // ---------------------------------------------------------------------
  52. template<typename T>
  53. struct StatementExpr0 {
  54. void f(T t) {
  55. (void)({
  56. if (t) // expected-error{{contextually convertible}}
  57. t = t + 17;
  58. t + 12; // expected-error{{invalid operands}}
  59. });
  60. }
  61. };
  62. template struct StatementExpr0<int>;
  63. template struct StatementExpr0<N1::X>; // expected-note{{instantiation}}
  64. // ---------------------------------------------------------------------
  65. // __builtin_choose_expr
  66. // ---------------------------------------------------------------------
  67. template<bool Cond, typename T, typename U, typename Result>
  68. struct Choose0 {
  69. void f(T t, U u) {
  70. Result r = __builtin_choose_expr(Cond, t, u); // expected-error{{lvalue}}
  71. }
  72. };
  73. template struct Choose0<true, int, float, int&>;
  74. template struct Choose0<false, int, float, float&>;
  75. template struct Choose0<true, int, float, float&>; // expected-note{{instantiation}}
  76. // ---------------------------------------------------------------------
  77. // __builtin_va_arg
  78. // ---------------------------------------------------------------------
  79. template<typename ArgType>
  80. struct VaArg0 {
  81. void f(int n, ...) {
  82. __builtin_va_list va;
  83. __builtin_va_start(va, n);
  84. for (int i = 0; i != n; ++i)
  85. (void)__builtin_va_arg(va, ArgType);
  86. __builtin_va_end(va);
  87. }
  88. };
  89. template struct VaArg0<int>;
  90. template<typename VaList, typename ArgType>
  91. struct VaArg1 {
  92. void f(int n, ...) {
  93. VaList va;
  94. __builtin_va_start(va, n); // expected-error{{int}}
  95. for (int i = 0; i != n; ++i)
  96. (void)__builtin_va_arg(va, ArgType); // expected-error{{int}}
  97. __builtin_va_end(va); // expected-error{{int}}
  98. }
  99. };
  100. template struct VaArg1<__builtin_va_list, int>;
  101. template struct VaArg1<int, int>; // expected-note{{instantiation}}