Douglas Gregor | d8ac436 | 2009-05-18 22:38:38 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -fsyntax-only -verify %s |
| 2 | |
Douglas Gregor | d5f3a0f | 2009-05-19 20:13:50 +0000 | [diff] [blame] | 3 | // --------------------------------------------------------------------- |
| 4 | // Imaginary literals |
| 5 | // --------------------------------------------------------------------- |
Douglas Gregor | d8ac436 | 2009-05-18 22:38:38 +0000 | [diff] [blame] | 6 | template<typename T> |
| 7 | struct ImaginaryLiteral0 { |
| 8 | void f(T &x) { |
| 9 | x = 3.0I; // expected-error{{incompatible type}} |
| 10 | } |
| 11 | }; |
| 12 | |
| 13 | template struct ImaginaryLiteral0<_Complex float>; |
| 14 | template struct ImaginaryLiteral0<int*>; // expected-note{{instantiation}} |
Douglas Gregor | 6731c31 | 2009-05-19 20:02:01 +0000 | [diff] [blame] | 15 | |
Douglas Gregor | d5f3a0f | 2009-05-19 20:13:50 +0000 | [diff] [blame] | 16 | // --------------------------------------------------------------------- |
| 17 | // Compound assignment operator |
| 18 | // --------------------------------------------------------------------- |
Douglas Gregor | 6731c31 | 2009-05-19 20:02:01 +0000 | [diff] [blame] | 19 | namespace N1 { |
| 20 | struct X { }; |
| 21 | |
| 22 | int& operator+=(X&, int); // expected-note{{candidate}} |
| 23 | } |
| 24 | |
| 25 | namespace N2 { |
| 26 | long& operator+=(N1::X&, long); // expected-note{{candidate}} |
| 27 | |
| 28 | template<typename T, typename U, typename Result> |
| 29 | struct PlusEquals0 { |
| 30 | void f(T t, U u) { |
| 31 | Result r = t += u; // expected-error{{ambiguous}} |
| 32 | } |
| 33 | }; |
| 34 | } |
| 35 | |
| 36 | namespace N3 { |
| 37 | struct Y : public N1::X { |
| 38 | short& operator+=(long); // expected-note{{candidate}} |
| 39 | }; |
| 40 | } |
| 41 | |
| 42 | template struct N2::PlusEquals0<N1::X, int, int&>; |
| 43 | template struct N2::PlusEquals0<N1::X, long, long&>; |
| 44 | template struct N2::PlusEquals0<N3::Y, long, short&>; |
| 45 | template struct N2::PlusEquals0<int, int, int&>; |
| 46 | template struct N2::PlusEquals0<N3::Y, int, short&>; // expected-note{{instantiation}} |
Douglas Gregor | d5f3a0f | 2009-05-19 20:13:50 +0000 | [diff] [blame] | 47 | |
| 48 | // --------------------------------------------------------------------- |
| 49 | // Conditional operator |
| 50 | // --------------------------------------------------------------------- |
| 51 | template<typename T, typename U, typename Result> |
| 52 | struct Conditional0 { |
| 53 | void f(T t, U u) { |
| 54 | Result result = t? : u; |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | template struct Conditional0<int, int, int>; |
Douglas Gregor | cd93817 | 2009-05-19 20:31:21 +0000 | [diff] [blame] | 59 | |
| 60 | // --------------------------------------------------------------------- |
| 61 | // Statement expressions |
| 62 | // --------------------------------------------------------------------- |
| 63 | template<typename T> |
| 64 | struct StatementExpr0 { |
| 65 | void f(T t) { |
| 66 | (void)({ if (t) t = t + 17; }); // expected-error{{invalid}} |
| 67 | } |
| 68 | }; |
| 69 | |
| 70 | template struct StatementExpr0<int>; |
| 71 | template struct StatementExpr0<N1::X>; // expected-note{{instantiation}} |
Douglas Gregor | dc241b4 | 2009-05-19 20:55:31 +0000 | [diff] [blame] | 72 | |
| 73 | // --------------------------------------------------------------------- |
Douglas Gregor | cde0173 | 2009-05-19 22:10:17 +0000 | [diff] [blame] | 74 | // __builtin_shufflevector |
| 75 | // --------------------------------------------------------------------- |
| 76 | typedef __attribute__(( ext_vector_type(2) )) double double2; |
Douglas Gregor | c9ecc57 | 2009-05-19 22:43:30 +0000 | [diff] [blame] | 77 | |
Douglas Gregor | cde0173 | 2009-05-19 22:10:17 +0000 | [diff] [blame] | 78 | template<typename T, typename U, int N, int M> |
| 79 | struct ShuffleVector0 { |
| 80 | void f(T t, U u, double2 a, double2 b) { |
| 81 | (void)__builtin_shufflevector(t, u, N, M); // expected-error{{index}} |
| 82 | (void)__builtin_shufflevector(a, b, N, M); |
| 83 | (void)__builtin_shufflevector(a, b, 2, 1); |
| 84 | } |
| 85 | }; |
| 86 | |
| 87 | template struct ShuffleVector0<double2, double2, 2, 1>; |
| 88 | template struct ShuffleVector0<double2, double2, 4, 3>; // expected-note{{instantiation}} |
Douglas Gregor | c9ecc57 | 2009-05-19 22:43:30 +0000 | [diff] [blame] | 89 | |
| 90 | // --------------------------------------------------------------------- |
| 91 | // __builtin_choose_expr |
| 92 | // --------------------------------------------------------------------- |
| 93 | template<bool Cond, typename T, typename U, typename Result> |
| 94 | struct Choose0 { |
| 95 | void f(T t, U u) { |
| 96 | Result r = __builtin_choose_expr(Cond, t, u); // expected-error{{lvalue}} |
| 97 | } |
| 98 | }; |
| 99 | |
| 100 | template struct Choose0<true, int, float, int&>; |
| 101 | template struct Choose0<false, int, float, float&>; |
| 102 | template struct Choose0<true, int, float, float&>; // expected-note{{instantiation}} |
Douglas Gregor | dd02730 | 2009-05-19 23:10:31 +0000 | [diff] [blame] | 103 | |
| 104 | // --------------------------------------------------------------------- |
Douglas Gregor | 0529519 | 2009-05-19 23:29:16 +0000 | [diff] [blame] | 105 | // __builtin_va_arg |
Douglas Gregor | dd02730 | 2009-05-19 23:10:31 +0000 | [diff] [blame] | 106 | // --------------------------------------------------------------------- |
| 107 | template<typename ArgType> |
| 108 | struct VaArg0 { |
| 109 | void f(int n, ...) { |
| 110 | __builtin_va_list va; |
| 111 | __builtin_va_start(va, n); |
| 112 | for (int i = 0; i != n; ++i) |
| 113 | (void)__builtin_va_arg(va, ArgType); |
| 114 | __builtin_va_end(va); |
| 115 | } |
| 116 | }; |
| 117 | |
| 118 | template struct VaArg0<int>; |
Douglas Gregor | 0529519 | 2009-05-19 23:29:16 +0000 | [diff] [blame] | 119 | |
Douglas Gregor | 96cff59 | 2009-05-20 18:50:16 +0000 | [diff] [blame] | 120 | template<typename VaList, typename ArgType> |
| 121 | struct VaArg1 { |
| 122 | void f(int n, ...) { |
| 123 | VaList va; |
Douglas Gregor | 0db2272 | 2009-05-20 20:30:46 +0000 | [diff] [blame^] | 124 | __builtin_va_start(va, n); // expected-error{{int}} |
Douglas Gregor | 96cff59 | 2009-05-20 18:50:16 +0000 | [diff] [blame] | 125 | for (int i = 0; i != n; ++i) |
| 126 | (void)__builtin_va_arg(va, ArgType); |
| 127 | __builtin_va_end(va); |
| 128 | } |
| 129 | }; |
| 130 | |
| 131 | template struct VaArg1<__builtin_va_list, int>; |
| 132 | template struct VaArg1<int, int>; // expected-note{{instantiation}} |
| 133 | |
Douglas Gregor | 0529519 | 2009-05-19 23:29:16 +0000 | [diff] [blame] | 134 | // --------------------------------------------------------------------- |
| 135 | // Vector element expressions |
| 136 | // --------------------------------------------------------------------- |
| 137 | #if 0 |
| 138 | // Not supported until we have full support for MemberExpr. |
| 139 | typedef __attribute__(( ext_vector_type(2) )) double double2; |
| 140 | typedef __attribute__(( ext_vector_type(4) )) double double4; |
| 141 | |
| 142 | template<typename T, typename U> |
| 143 | struct VectorElem0 { |
| 144 | void f(T t, U u) { |
| 145 | t.xy = u.zw; |
| 146 | } |
| 147 | }; |
| 148 | |
| 149 | template struct VectorElem0<double2, double4>; |
| 150 | template struct VectorElem0<double4, double4>; |
| 151 | #endif |