instantiate-expr-3.cpp revision dd0273078111ec7312172c456a01ff86bff83b23
1// RUN: clang-cc -fsyntax-only -verify %s 2 3// --------------------------------------------------------------------- 4// Imaginary literals 5// --------------------------------------------------------------------- 6template<typename T> 7struct ImaginaryLiteral0 { 8 void f(T &x) { 9 x = 3.0I; // expected-error{{incompatible type}} 10 } 11}; 12 13template struct ImaginaryLiteral0<_Complex float>; 14template struct ImaginaryLiteral0<int*>; // expected-note{{instantiation}} 15 16// --------------------------------------------------------------------- 17// Compound assignment operator 18// --------------------------------------------------------------------- 19namespace N1 { 20 struct X { }; 21 22 int& operator+=(X&, int); // expected-note{{candidate}} 23} 24 25namespace 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 36namespace N3 { 37 struct Y : public N1::X { 38 short& operator+=(long); // expected-note{{candidate}} 39 }; 40} 41 42template struct N2::PlusEquals0<N1::X, int, int&>; 43template struct N2::PlusEquals0<N1::X, long, long&>; 44template struct N2::PlusEquals0<N3::Y, long, short&>; 45template struct N2::PlusEquals0<int, int, int&>; 46template struct N2::PlusEquals0<N3::Y, int, short&>; // expected-note{{instantiation}} 47 48// --------------------------------------------------------------------- 49// Conditional operator 50// --------------------------------------------------------------------- 51template<typename T, typename U, typename Result> 52struct Conditional0 { 53 void f(T t, U u) { 54 Result result = t? : u; 55 } 56}; 57 58template struct Conditional0<int, int, int>; 59 60// --------------------------------------------------------------------- 61// Statement expressions 62// --------------------------------------------------------------------- 63template<typename T> 64struct StatementExpr0 { 65 void f(T t) { 66 (void)({ if (t) t = t + 17; }); // expected-error{{invalid}} 67 } 68}; 69 70template struct StatementExpr0<int>; 71template struct StatementExpr0<N1::X>; // expected-note{{instantiation}} 72 73// --------------------------------------------------------------------- 74// __builtin_shufflevector 75// --------------------------------------------------------------------- 76typedef __attribute__(( ext_vector_type(2) )) double double2; 77 78template<typename T, typename U, int N, int M> 79struct 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 87template struct ShuffleVector0<double2, double2, 2, 1>; 88template struct ShuffleVector0<double2, double2, 4, 3>; // expected-note{{instantiation}} 89 90// --------------------------------------------------------------------- 91// __builtin_choose_expr 92// --------------------------------------------------------------------- 93template<bool Cond, typename T, typename U, typename Result> 94struct Choose0 { 95 void f(T t, U u) { 96 Result r = __builtin_choose_expr(Cond, t, u); // expected-error{{lvalue}} 97 } 98}; 99 100template struct Choose0<true, int, float, int&>; 101template struct Choose0<false, int, float, float&>; 102template struct Choose0<true, int, float, float&>; // expected-note{{instantiation}} 103 104// --------------------------------------------------------------------- 105// va_arg 106// --------------------------------------------------------------------- 107template<typename ArgType> 108struct 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 118template struct VaArg0<int>; 119