blob: 696b58325cd70a3c651c3d9fd6d4eb554a7b0da1 [file] [log] [blame]
Douglas Gregord8ac4362009-05-18 22:38:38 +00001// RUN: clang-cc -fsyntax-only -verify %s
2
Douglas Gregord5f3a0f2009-05-19 20:13:50 +00003// ---------------------------------------------------------------------
4// Imaginary literals
5// ---------------------------------------------------------------------
Douglas Gregord8ac4362009-05-18 22:38:38 +00006template<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}}
Douglas Gregor6731c312009-05-19 20:02:01 +000015
Douglas Gregord5f3a0f2009-05-19 20:13:50 +000016// ---------------------------------------------------------------------
17// Compound assignment operator
18// ---------------------------------------------------------------------
Douglas Gregor6731c312009-05-19 20:02:01 +000019namespace 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}}
Douglas Gregord5f3a0f2009-05-19 20:13:50 +000047
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>;
Douglas Gregorcd938172009-05-19 20:31:21 +000059
60// ---------------------------------------------------------------------
61// Statement expressions
62// ---------------------------------------------------------------------
63template<typename T>
64struct StatementExpr0 {
65 void f(T t) {
Douglas Gregor66b46be2009-05-20 22:57:03 +000066 (void)({ if (t) t = t + 17; t + 12;}); // expected-error{{invalid}}
Douglas Gregorcd938172009-05-19 20:31:21 +000067 }
68};
69
70template struct StatementExpr0<int>;
71template struct StatementExpr0<N1::X>; // expected-note{{instantiation}}
Douglas Gregordc241b42009-05-19 20:55:31 +000072
73// ---------------------------------------------------------------------
Douglas Gregorc9ecc572009-05-19 22:43:30 +000074// __builtin_choose_expr
75// ---------------------------------------------------------------------
76template<bool Cond, typename T, typename U, typename Result>
77struct Choose0 {
78 void f(T t, U u) {
79 Result r = __builtin_choose_expr(Cond, t, u); // expected-error{{lvalue}}
80 }
81};
82
83template struct Choose0<true, int, float, int&>;
84template struct Choose0<false, int, float, float&>;
85template struct Choose0<true, int, float, float&>; // expected-note{{instantiation}}
Douglas Gregordd027302009-05-19 23:10:31 +000086
87// ---------------------------------------------------------------------
Douglas Gregor05295192009-05-19 23:29:16 +000088// __builtin_va_arg
Douglas Gregordd027302009-05-19 23:10:31 +000089// ---------------------------------------------------------------------
90template<typename ArgType>
91struct VaArg0 {
92 void f(int n, ...) {
93 __builtin_va_list va;
94 __builtin_va_start(va, n);
95 for (int i = 0; i != n; ++i)
96 (void)__builtin_va_arg(va, ArgType);
97 __builtin_va_end(va);
98 }
99};
100
101template struct VaArg0<int>;
Douglas Gregor05295192009-05-19 23:29:16 +0000102
Douglas Gregor96cff592009-05-20 18:50:16 +0000103template<typename VaList, typename ArgType>
104struct VaArg1 {
105 void f(int n, ...) {
106 VaList va;
Douglas Gregor0db22722009-05-20 20:30:46 +0000107 __builtin_va_start(va, n); // expected-error{{int}}
Douglas Gregor96cff592009-05-20 18:50:16 +0000108 for (int i = 0; i != n; ++i)
109 (void)__builtin_va_arg(va, ArgType);
110 __builtin_va_end(va);
111 }
112};
113
114template struct VaArg1<__builtin_va_list, int>;
115template struct VaArg1<int, int>; // expected-note{{instantiation}}