1a5728872c7702ddd09537c95bc3cbd20e1f2fb09Daniel Dunbar// RUN: %clang_cc1 -fsyntax-only -verify %s
2eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregorclass X { };
3eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor
4eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas GregorX operator+(X, X);
5eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor
6eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregorvoid f(X x) {
7eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor  x = x + x;
8eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor}
9eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor
10eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregorstruct Y;
11eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregorstruct Z;
12eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor
13eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregorstruct Y {
14eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor  Y(const Z&);
15eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor};
16eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor
17eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregorstruct Z {
18eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor  Z(const Y&);
19eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor};
20eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor
21eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas GregorY operator+(Y, Y);
22eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregorbool operator-(Y, Y); // expected-note{{candidate function}}
23eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregorbool operator-(Z, Z); // expected-note{{candidate function}}
24eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor
25eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregorvoid g(Y y, Z z) {
26eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor  y = y + z;
27ae2cf767de457df939d07c44b162de5fe0b5e607Douglas Gregor  bool b = y - z; // expected-error{{use of overloaded operator '-' is ambiguous}}
28eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor}
29eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor
3096176b3575823ea996c6140380dd17d9240c9766Douglas Gregorstruct A {
313307475eb0dd6e5d88be9392ea8247d0b6b812dfDouglas Gregor  bool operator==(Z&); // expected-note 2{{candidate function}}
3296176b3575823ea996c6140380dd17d9240c9766Douglas Gregor};
3396176b3575823ea996c6140380dd17d9240c9766Douglas Gregor
3496176b3575823ea996c6140380dd17d9240c9766Douglas GregorA make_A();
35eaebc75ef6ff21fbc9f25ab4175cba465e4e0e43Douglas Gregor
36439d3c3d76f858df5f25239f2a70f04312eacb5bDouglas Gregorbool operator==(A&, Z&); // expected-note 3{{candidate function}}
3796176b3575823ea996c6140380dd17d9240c9766Douglas Gregor
3896176b3575823ea996c6140380dd17d9240c9766Douglas Gregorvoid h(A a, const A ac, Z z) {
399b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth  make_A() == z; // expected-warning{{equality comparison result unused}}
40ae2cf767de457df939d07c44b162de5fe0b5e607Douglas Gregor  a == z; // expected-error{{use of overloaded operator '==' is ambiguous}}
410c42bb653dc40b1caae010618831e320af824b18Chris Lattner  ac == z; // expected-error{{invalid operands to binary expression ('const A' and 'Z')}}
4296176b3575823ea996c6140380dd17d9240c9766Douglas Gregor}
4396176b3575823ea996c6140380dd17d9240c9766Douglas Gregor
4496176b3575823ea996c6140380dd17d9240c9766Douglas Gregorstruct B {
4596176b3575823ea996c6140380dd17d9240c9766Douglas Gregor  bool operator==(const B&) const;
4696176b3575823ea996c6140380dd17d9240c9766Douglas Gregor
4796176b3575823ea996c6140380dd17d9240c9766Douglas Gregor  void test(Z z) {
489b10683a3f222d8dc6e139073ca96b97b439747bChandler Carruth    make_A() == z; // expected-warning{{equality comparison result unused}}
4996176b3575823ea996c6140380dd17d9240c9766Douglas Gregor  }
5096176b3575823ea996c6140380dd17d9240c9766Douglas Gregor};
51447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregor
52d64fdd0c056f1e50488519254f852fa8050f0470Douglas Gregor// we shouldn't see warnings about self-comparison,
53d64fdd0c056f1e50488519254f852fa8050f0470Douglas Gregor// this is a member function, we dunno what it'll do
54d64fdd0c056f1e50488519254f852fa8050f0470Douglas Gregorbool i(B b)
55d64fdd0c056f1e50488519254f852fa8050f0470Douglas Gregor{
56d64fdd0c056f1e50488519254f852fa8050f0470Douglas Gregor  return b == b;
57d64fdd0c056f1e50488519254f852fa8050f0470Douglas Gregor}
58d64fdd0c056f1e50488519254f852fa8050f0470Douglas Gregor
59447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregorenum Enum1 { };
60447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregorenum Enum2 { };
61447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregor
62447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregorstruct E1 {
63447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregor  E1(Enum1) { }
64447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregor};
65447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregor
66447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregorstruct E2 {
67447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregor  E2(Enum2);
68447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregor};
69447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregor
70447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregor// C++ [over.match.oper]p3 - enum restriction.
71439d3c3d76f858df5f25239f2a70f04312eacb5bDouglas Gregorfloat& operator==(E1, E2);  // expected-note{{candidate function}}
72447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregor
73543cb655b174087f6c2d22009934c9fed6c32114Chandler Carruthvoid enum_test(Enum1 enum1, Enum2 enum2, E1 e1, E2 e2, Enum1 next_enum1) {
74447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregor  float &f1 = (e1 == e2);
75447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregor  float &f2 = (enum1 == e2);
76447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregor  float &f3 = (e1 == enum2);
77543cb655b174087f6c2d22009934c9fed6c32114Chandler Carruth  float &f4 = (enum1 == next_enum1);  // expected-error{{non-const lvalue reference to type 'float' cannot bind to a temporary of type 'bool'}}
78447b69e55e1098d8df46dd99f171bfaace9ff8a0Douglas Gregor}
7974253736184c0717a0649922551bf9d8b6815651Douglas Gregor
80644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl// PR5244 - Argument-dependent lookup would include the two operators below,
81644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl// which would break later assumptions and lead to a crash.
82644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redlclass pr5244_foo
83644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl{
84644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl  pr5244_foo(int);
85644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl  pr5244_foo(char);
86644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl};
87644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl
88439d3c3d76f858df5f25239f2a70f04312eacb5bDouglas Gregorbool operator==(const pr5244_foo& s1, const pr5244_foo& s2); // expected-note{{candidate function}}
89439d3c3d76f858df5f25239f2a70f04312eacb5bDouglas Gregorbool operator==(char c, const pr5244_foo& s); // expected-note{{candidate function}}
90644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl
91644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redlenum pr5244_bar
92644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl{
93644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl    pr5244_BAR
94644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl};
95644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl
96644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redlclass pr5244_baz
97644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl{
987002f4c03c2d0544f4e8bea8d3a5636519081e35John McCallpublic:
99644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl    pr5244_bar quux;
100644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl};
101644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl
102644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redlvoid pr5244_barbaz()
103644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl{
104644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl  pr5244_baz quuux;
105644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl  (void)(pr5244_BAR == quuux.quux);
106644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl}
107644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl
108644be853b87cae94fcabaf309a5e482a8c291fb9Sebastian Redl
10974253736184c0717a0649922551bf9d8b6815651Douglas Gregor
11074253736184c0717a0649922551bf9d8b6815651Douglas Gregorstruct PostInc {
11174253736184c0717a0649922551bf9d8b6815651Douglas Gregor  PostInc operator++(int);
11274253736184c0717a0649922551bf9d8b6815651Douglas Gregor  PostInc& operator++();
11374253736184c0717a0649922551bf9d8b6815651Douglas Gregor};
11474253736184c0717a0649922551bf9d8b6815651Douglas Gregor
11574253736184c0717a0649922551bf9d8b6815651Douglas Gregorstruct PostDec {
11674253736184c0717a0649922551bf9d8b6815651Douglas Gregor  PostDec operator--(int);
11774253736184c0717a0649922551bf9d8b6815651Douglas Gregor  PostDec& operator--();
11874253736184c0717a0649922551bf9d8b6815651Douglas Gregor};
11974253736184c0717a0649922551bf9d8b6815651Douglas Gregor
12074253736184c0717a0649922551bf9d8b6815651Douglas Gregorvoid incdec_test(PostInc pi, PostDec pd) {
12174253736184c0717a0649922551bf9d8b6815651Douglas Gregor  const PostInc& pi1 = pi++;
12274253736184c0717a0649922551bf9d8b6815651Douglas Gregor  const PostDec& pd1 = pd--;
12374253736184c0717a0649922551bf9d8b6815651Douglas Gregor  PostInc &pi2 = ++pi;
12474253736184c0717a0649922551bf9d8b6815651Douglas Gregor  PostDec &pd2 = --pd;
12574253736184c0717a0649922551bf9d8b6815651Douglas Gregor}
12674253736184c0717a0649922551bf9d8b6815651Douglas Gregor
12774253736184c0717a0649922551bf9d8b6815651Douglas Gregorstruct SmartPtr {
12874253736184c0717a0649922551bf9d8b6815651Douglas Gregor  int& operator*();
1291ca50c3f541dd637063b9d186a7ea193e3440a48Douglas Gregor  long& operator*() const volatile;
13074253736184c0717a0649922551bf9d8b6815651Douglas Gregor};
13174253736184c0717a0649922551bf9d8b6815651Douglas Gregor
1321ca50c3f541dd637063b9d186a7ea193e3440a48Douglas Gregorvoid test_smartptr(SmartPtr ptr, const SmartPtr cptr,
1331ca50c3f541dd637063b9d186a7ea193e3440a48Douglas Gregor                   const volatile SmartPtr cvptr) {
13474253736184c0717a0649922551bf9d8b6815651Douglas Gregor  int &ir = *ptr;
1351ca50c3f541dd637063b9d186a7ea193e3440a48Douglas Gregor  long &lr = *cptr;
1361ca50c3f541dd637063b9d186a7ea193e3440a48Douglas Gregor  long &lr2 = *cvptr;
13774253736184c0717a0649922551bf9d8b6815651Douglas Gregor}
138337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor
139337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor
140337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregorstruct ArrayLike {
141337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor  int& operator[](int);
142337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor};
143337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor
144337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregorvoid test_arraylike(ArrayLike a) {
145337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor  int& ir = a[17];
146337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor}
147337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor
148337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregorstruct SmartRef {
149337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor  int* operator&();
150337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor};
151337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor
152337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregorvoid test_smartref(SmartRef r) {
153337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor  int* ip = &r;
154337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor}
155337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor
156337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregorbool& operator,(X, Y);
157337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor
158337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregorvoid test_comma(X x, Y y) {
159337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor  bool& b1 = (x, y);
1601b2ad2fd9e2d5352144481aa1fd995d333d9adc9Argyrios Kyrtzidis  X& xr = (x, x); // expected-warning {{expression result unused}}
161337c6b9f5d502dc1c5acea628bf7bf9e828efc0eDouglas Gregor}
162f9eb905197e44ed5634205512074993f6f40470dDouglas Gregor
163f9eb905197e44ed5634205512074993f6f40470dDouglas Gregorstruct Callable {
164f9eb905197e44ed5634205512074993f6f40470dDouglas Gregor  int& operator()(int, double = 2.71828); // expected-note{{candidate function}}
165f9eb905197e44ed5634205512074993f6f40470dDouglas Gregor  float& operator()(int, double, long, ...); // expected-note{{candidate function}}
166518fda1d121dcba3ad7276f5e9a94f733f6e5ecdDouglas Gregor
167518fda1d121dcba3ad7276f5e9a94f733f6e5ecdDouglas Gregor  double& operator()(float); // expected-note{{candidate function}}
168518fda1d121dcba3ad7276f5e9a94f733f6e5ecdDouglas Gregor};
169518fda1d121dcba3ad7276f5e9a94f733f6e5ecdDouglas Gregor
170518fda1d121dcba3ad7276f5e9a94f733f6e5ecdDouglas Gregorstruct Callable2 {
171518fda1d121dcba3ad7276f5e9a94f733f6e5ecdDouglas Gregor  int& operator()(int i = 0);
172518fda1d121dcba3ad7276f5e9a94f733f6e5ecdDouglas Gregor  double& operator()(...) const;
173f9eb905197e44ed5634205512074993f6f40470dDouglas Gregor};
174f9eb905197e44ed5634205512074993f6f40470dDouglas Gregor
175593564ba94ff854b7a410a4ca17ad34a90c5b761Douglas Gregorstruct DerivesCallable : public Callable {
176593564ba94ff854b7a410a4ca17ad34a90c5b761Douglas Gregor};
177593564ba94ff854b7a410a4ca17ad34a90c5b761Douglas Gregor
178593564ba94ff854b7a410a4ca17ad34a90c5b761Douglas Gregorvoid test_callable(Callable c, Callable2 c2, const Callable2& c2c,
179593564ba94ff854b7a410a4ca17ad34a90c5b761Douglas Gregor                   DerivesCallable dc) {
180f9eb905197e44ed5634205512074993f6f40470dDouglas Gregor  int &ir = c(1);
181f9eb905197e44ed5634205512074993f6f40470dDouglas Gregor  float &fr = c(1, 3.14159, 17, 42);
182f9eb905197e44ed5634205512074993f6f40470dDouglas Gregor
1837c2342dd4c9947806842e5aca3d2bb2e542853c9John McCall  c(); // expected-error{{no matching function for call to object of type 'Callable'}}
184518fda1d121dcba3ad7276f5e9a94f733f6e5ecdDouglas Gregor
185518fda1d121dcba3ad7276f5e9a94f733f6e5ecdDouglas Gregor  double &dr = c(1.0f);
186518fda1d121dcba3ad7276f5e9a94f733f6e5ecdDouglas Gregor
187518fda1d121dcba3ad7276f5e9a94f733f6e5ecdDouglas Gregor  int &ir2 = c2();
188518fda1d121dcba3ad7276f5e9a94f733f6e5ecdDouglas Gregor  int &ir3 = c2(1);
189518fda1d121dcba3ad7276f5e9a94f733f6e5ecdDouglas Gregor  double &fr2 = c2c();
190593564ba94ff854b7a410a4ca17ad34a90c5b761Douglas Gregor
191593564ba94ff854b7a410a4ca17ad34a90c5b761Douglas Gregor  int &ir4 = dc(17);
192593564ba94ff854b7a410a4ca17ad34a90c5b761Douglas Gregor  double &fr3 = dc(3.14159f);
193f9eb905197e44ed5634205512074993f6f40470dDouglas Gregor}
194106c6eb3f1380bfe243a62d8f0f8bce6a7c8d5c6Douglas Gregor
195621b3933e570792810386b891264c78e3bd7b169Douglas Gregortypedef float FLOAT;
196621b3933e570792810386b891264c78e3bd7b169Douglas Gregortypedef int& INTREF;
197621b3933e570792810386b891264c78e3bd7b169Douglas Gregortypedef INTREF Func1(FLOAT, double);
198106c6eb3f1380bfe243a62d8f0f8bce6a7c8d5c6Douglas Gregortypedef float& Func2(int, double);
199106c6eb3f1380bfe243a62d8f0f8bce6a7c8d5c6Douglas Gregor
200106c6eb3f1380bfe243a62d8f0f8bce6a7c8d5c6Douglas Gregorstruct ConvertToFunc {
2019007328043c9c17029e07c99d89d0488fb3da3a7Douglas Gregor  operator Func1*(); // expected-note 2{{conversion candidate of type 'INTREF (*)(FLOAT, double)'}}
2029007328043c9c17029e07c99d89d0488fb3da3a7Douglas Gregor  operator Func2&(); // expected-note 2{{conversion candidate of type 'float &(&)(int, double)'}}
2039ebae31a97f862771dc5f6bd4923dd97131fed71Douglas Gregor  void operator()();
204106c6eb3f1380bfe243a62d8f0f8bce6a7c8d5c6Douglas Gregor};
205106c6eb3f1380bfe243a62d8f0f8bce6a7c8d5c6Douglas Gregor
2069007328043c9c17029e07c99d89d0488fb3da3a7Douglas Gregorstruct ConvertToFuncDerived : ConvertToFunc { };
2079007328043c9c17029e07c99d89d0488fb3da3a7Douglas Gregor
2089007328043c9c17029e07c99d89d0488fb3da3a7Douglas Gregorvoid test_funcptr_call(ConvertToFunc ctf, ConvertToFuncDerived ctfd) {
209106c6eb3f1380bfe243a62d8f0f8bce6a7c8d5c6Douglas Gregor  int &i1 = ctf(1.0f, 2.0);
2109007328043c9c17029e07c99d89d0488fb3da3a7Douglas Gregor  float &f1 = ctf((short int)1, 1.0f);
2117c2342dd4c9947806842e5aca3d2bb2e542853c9John McCall  ctf((long int)17, 2.0); // expected-error{{call to object of type 'ConvertToFunc' is ambiguous}}
2129ebae31a97f862771dc5f6bd4923dd97131fed71Douglas Gregor  ctf();
2139007328043c9c17029e07c99d89d0488fb3da3a7Douglas Gregor
2149007328043c9c17029e07c99d89d0488fb3da3a7Douglas Gregor  int &i2 = ctfd(1.0f, 2.0);
2159007328043c9c17029e07c99d89d0488fb3da3a7Douglas Gregor  float &f2 = ctfd((short int)1, 1.0f);
2167c2342dd4c9947806842e5aca3d2bb2e542853c9John McCall  ctfd((long int)17, 2.0); // expected-error{{call to object of type 'ConvertToFuncDerived' is ambiguous}}
2179007328043c9c17029e07c99d89d0488fb3da3a7Douglas Gregor  ctfd();
218106c6eb3f1380bfe243a62d8f0f8bce6a7c8d5c6Douglas Gregor}
2198ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregor
2208ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregorstruct HasMember {
2218ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregor  int m;
2228ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregor};
2238ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregor
2248ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregorstruct Arrow1 {
2258ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregor  HasMember* operator->();
2268ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregor};
2278ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregor
2288ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregorstruct Arrow2 {
2298ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregor  Arrow1 operator->(); // expected-note{{candidate function}}
2308ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregor};
2318ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregor
2328ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregorvoid test_arrow(Arrow1 a1, Arrow2 a2, const Arrow2 a3) {
2338ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregor  int &i1 = a1->m;
2348ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregor  int &i2 = a2->m;
235e4c452c4c7b9124fe94a96f559ff077d59cdf996Sebastian Redl  a3->m; // expected-error{{no viable overloaded 'operator->'; candidate is}}
2368ba10745f525467e91bbaec21044bf4d9017a988Douglas Gregor}
237e63ef48b76b84e7ffb0a38fbf475ddea5c48adb4Douglas Gregor
238e63ef48b76b84e7ffb0a38fbf475ddea5c48adb4Douglas Gregorstruct CopyConBase {
239e63ef48b76b84e7ffb0a38fbf475ddea5c48adb4Douglas Gregor};
240e63ef48b76b84e7ffb0a38fbf475ddea5c48adb4Douglas Gregor
241e63ef48b76b84e7ffb0a38fbf475ddea5c48adb4Douglas Gregorstruct CopyCon : public CopyConBase {
242e63ef48b76b84e7ffb0a38fbf475ddea5c48adb4Douglas Gregor  CopyCon(const CopyConBase &Base);
243e63ef48b76b84e7ffb0a38fbf475ddea5c48adb4Douglas Gregor
244e63ef48b76b84e7ffb0a38fbf475ddea5c48adb4Douglas Gregor  CopyCon(const CopyConBase *Base) {
245e63ef48b76b84e7ffb0a38fbf475ddea5c48adb4Douglas Gregor    *this = *Base;
246e63ef48b76b84e7ffb0a38fbf475ddea5c48adb4Douglas Gregor  }
247e63ef48b76b84e7ffb0a38fbf475ddea5c48adb4Douglas Gregor};
248fa047648b2a5502d7eef117adb4777eb9a63baa6Douglas Gregor
249fa047648b2a5502d7eef117adb4777eb9a63baa6Douglas Gregornamespace N {
250fa047648b2a5502d7eef117adb4777eb9a63baa6Douglas Gregor  struct X { };
251fa047648b2a5502d7eef117adb4777eb9a63baa6Douglas Gregor}
252fa047648b2a5502d7eef117adb4777eb9a63baa6Douglas Gregor
253fa047648b2a5502d7eef117adb4777eb9a63baa6Douglas Gregornamespace M {
254fa047648b2a5502d7eef117adb4777eb9a63baa6Douglas Gregor  N::X operator+(N::X, N::X);
255fa047648b2a5502d7eef117adb4777eb9a63baa6Douglas Gregor}
256fa047648b2a5502d7eef117adb4777eb9a63baa6Douglas Gregor
257fa047648b2a5502d7eef117adb4777eb9a63baa6Douglas Gregornamespace M {
258fa047648b2a5502d7eef117adb4777eb9a63baa6Douglas Gregor  void test_X(N::X x) {
259f680a0fe2dcab32b59fe6fdf71145b5313c40950Douglas Gregor    (void)(x + x);
260fa047648b2a5502d7eef117adb4777eb9a63baa6Douglas Gregor  }
261fa047648b2a5502d7eef117adb4777eb9a63baa6Douglas Gregor}
2628a5ae2401645788144c0ae769a2fb899866801f5Douglas Gregor
2638a5ae2401645788144c0ae769a2fb899866801f5Douglas Gregorstruct AA { bool operator!=(AA&); };
2648a5ae2401645788144c0ae769a2fb899866801f5Douglas Gregorstruct BB : AA {};
2658a5ae2401645788144c0ae769a2fb899866801f5Douglas Gregorbool x(BB y, BB z) { return y != z; }
2664a4e345a8bf749b5462a127ecfb1f90d4a9d6ba7Fariborz Jahanian
2674a4e345a8bf749b5462a127ecfb1f90d4a9d6ba7Fariborz Jahanian
2684a4e345a8bf749b5462a127ecfb1f90d4a9d6ba7Fariborz Jahanianstruct AX {
269d1aa800a19c956c72319025dd302ae78ed47f9eeAnders Carlsson  AX& operator ->();	 // expected-note {{declared here}}
2704a4e345a8bf749b5462a127ecfb1f90d4a9d6ba7Fariborz Jahanian  int b;
2714a4e345a8bf749b5462a127ecfb1f90d4a9d6ba7Fariborz Jahanian};
2724a4e345a8bf749b5462a127ecfb1f90d4a9d6ba7Fariborz Jahanian
2734a4e345a8bf749b5462a127ecfb1f90d4a9d6ba7Fariborz Jahanianvoid m() {
2744a4e345a8bf749b5462a127ecfb1f90d4a9d6ba7Fariborz Jahanian  AX a;
2754a4e345a8bf749b5462a127ecfb1f90d4a9d6ba7Fariborz Jahanian  a->b = 0; // expected-error {{circular pointer delegation detected}}
2764a4e345a8bf749b5462a127ecfb1f90d4a9d6ba7Fariborz Jahanian}
277c4e8321deb2bd83f734a09749460050f40ec51d1John McCall
278c4e8321deb2bd83f734a09749460050f40ec51d1John McCallstruct CircA {
279d1aa800a19c956c72319025dd302ae78ed47f9eeAnders Carlsson  struct CircB& operator->(); // expected-note {{declared here}}
280c4e8321deb2bd83f734a09749460050f40ec51d1John McCall  int val;
281c4e8321deb2bd83f734a09749460050f40ec51d1John McCall};
282c4e8321deb2bd83f734a09749460050f40ec51d1John McCallstruct CircB {
283d1aa800a19c956c72319025dd302ae78ed47f9eeAnders Carlsson  struct CircC& operator->(); // expected-note {{declared here}}
284c4e8321deb2bd83f734a09749460050f40ec51d1John McCall};
285c4e8321deb2bd83f734a09749460050f40ec51d1John McCallstruct CircC {
286d1aa800a19c956c72319025dd302ae78ed47f9eeAnders Carlsson  struct CircA& operator->(); // expected-note {{declared here}}
287c4e8321deb2bd83f734a09749460050f40ec51d1John McCall};
288c4e8321deb2bd83f734a09749460050f40ec51d1John McCall
289c4e8321deb2bd83f734a09749460050f40ec51d1John McCallvoid circ() {
290c4e8321deb2bd83f734a09749460050f40ec51d1John McCall  CircA a;
291c4e8321deb2bd83f734a09749460050f40ec51d1John McCall  a->val = 0; // expected-error {{circular pointer delegation detected}}
292c4e8321deb2bd83f734a09749460050f40ec51d1John McCall}
293a65b55142bd8e8c94f371bb056d8f58f11de220fSebastian Redl
294a65b55142bd8e8c94f371bb056d8f58f11de220fSebastian Redl// PR5360: Arrays should lead to built-in candidates for subscript.
295a65b55142bd8e8c94f371bb056d8f58f11de220fSebastian Redltypedef enum {
2966d82ef45d624da4fc88a2fbf7dd1dc144aeb05b0Douglas Gregor  LastReg = 23,
297a65b55142bd8e8c94f371bb056d8f58f11de220fSebastian Redl} Register;
298a65b55142bd8e8c94f371bb056d8f58f11de220fSebastian Redlclass RegAlloc {
299a65b55142bd8e8c94f371bb056d8f58f11de220fSebastian Redl  int getPriority(Register r) {
300a65b55142bd8e8c94f371bb056d8f58f11de220fSebastian Redl    return usepri[r];
301a65b55142bd8e8c94f371bb056d8f58f11de220fSebastian Redl  }
302a65b55142bd8e8c94f371bb056d8f58f11de220fSebastian Redl  int usepri[LastReg + 1];
303a65b55142bd8e8c94f371bb056d8f58f11de220fSebastian Redl};
304a9efadada0430493a4d68b34b2e76580d0fd8f10Sebastian Redl
305a9efadada0430493a4d68b34b2e76580d0fd8f10Sebastian Redl// PR5546: Don't generate incorrect and ambiguous overloads for multi-level
306a9efadada0430493a4d68b34b2e76580d0fd8f10Sebastian Redl// arrays.
307a9efadada0430493a4d68b34b2e76580d0fd8f10Sebastian Redlnamespace pr5546
308a9efadada0430493a4d68b34b2e76580d0fd8f10Sebastian Redl{
309a9efadada0430493a4d68b34b2e76580d0fd8f10Sebastian Redl  enum { X };
310a9efadada0430493a4d68b34b2e76580d0fd8f10Sebastian Redl  extern const char *const sMoveCommands[][2][2];
311a9efadada0430493a4d68b34b2e76580d0fd8f10Sebastian Redl  const char* a() { return sMoveCommands[X][0][0]; }
312a9efadada0430493a4d68b34b2e76580d0fd8f10Sebastian Redl  const char* b() { return (*(sMoveCommands+X))[0][0]; }
313a9efadada0430493a4d68b34b2e76580d0fd8f10Sebastian Redl}
314275c2b47a1dc200d6b55dd867bdfeb7a91b8d876Sebastian Redl
315275c2b47a1dc200d6b55dd867bdfeb7a91b8d876Sebastian Redl// PR5512 and its discussion
316275c2b47a1dc200d6b55dd867bdfeb7a91b8d876Sebastian Redlnamespace pr5512 {
317275c2b47a1dc200d6b55dd867bdfeb7a91b8d876Sebastian Redl  struct Y {
318275c2b47a1dc200d6b55dd867bdfeb7a91b8d876Sebastian Redl    operator short();
319275c2b47a1dc200d6b55dd867bdfeb7a91b8d876Sebastian Redl    operator float();
320275c2b47a1dc200d6b55dd867bdfeb7a91b8d876Sebastian Redl  };
321275c2b47a1dc200d6b55dd867bdfeb7a91b8d876Sebastian Redl  void g_test(Y y) {
322275c2b47a1dc200d6b55dd867bdfeb7a91b8d876Sebastian Redl    short s = 0;
323275c2b47a1dc200d6b55dd867bdfeb7a91b8d876Sebastian Redl    // DR507, this should be ambiguous, but we special-case assignment
324275c2b47a1dc200d6b55dd867bdfeb7a91b8d876Sebastian Redl    s = y;
325275c2b47a1dc200d6b55dd867bdfeb7a91b8d876Sebastian Redl    // Note: DR507, this is ambiguous as specified
326275c2b47a1dc200d6b55dd867bdfeb7a91b8d876Sebastian Redl    //s += y;
327275c2b47a1dc200d6b55dd867bdfeb7a91b8d876Sebastian Redl  }
328275c2b47a1dc200d6b55dd867bdfeb7a91b8d876Sebastian Redl
329275c2b47a1dc200d6b55dd867bdfeb7a91b8d876Sebastian Redl  struct S {};
330275c2b47a1dc200d6b55dd867bdfeb7a91b8d876Sebastian Redl  void operator +=(int&, S);
331275c2b47a1dc200d6b55dd867bdfeb7a91b8d876Sebastian Redl  void f(S s) {
332275c2b47a1dc200d6b55dd867bdfeb7a91b8d876Sebastian Redl    int i = 0;
333275c2b47a1dc200d6b55dd867bdfeb7a91b8d876Sebastian Redl    i += s;
334275c2b47a1dc200d6b55dd867bdfeb7a91b8d876Sebastian Redl  }
335275c2b47a1dc200d6b55dd867bdfeb7a91b8d876Sebastian Redl
336275c2b47a1dc200d6b55dd867bdfeb7a91b8d876Sebastian Redl  struct A {operator int();};
337275c2b47a1dc200d6b55dd867bdfeb7a91b8d876Sebastian Redl  int a;
338275c2b47a1dc200d6b55dd867bdfeb7a91b8d876Sebastian Redl  void b(A x) {
339275c2b47a1dc200d6b55dd867bdfeb7a91b8d876Sebastian Redl    a += x;
340275c2b47a1dc200d6b55dd867bdfeb7a91b8d876Sebastian Redl  }
341275c2b47a1dc200d6b55dd867bdfeb7a91b8d876Sebastian Redl}
3421eb3e1003d5cda4d47f54321d81d678c26981e7aJohn McCall
3431eb3e1003d5cda4d47f54321d81d678c26981e7aJohn McCall// PR5900
3441eb3e1003d5cda4d47f54321d81d678c26981e7aJohn McCallnamespace pr5900 {
3451eb3e1003d5cda4d47f54321d81d678c26981e7aJohn McCall  struct NotAnArray {};
3461eb3e1003d5cda4d47f54321d81d678c26981e7aJohn McCall  void test0() {
3471eb3e1003d5cda4d47f54321d81d678c26981e7aJohn McCall    NotAnArray x;
3481eb3e1003d5cda4d47f54321d81d678c26981e7aJohn McCall    x[0] = 0; // expected-error {{does not provide a subscript operator}}
3491eb3e1003d5cda4d47f54321d81d678c26981e7aJohn McCall  }
3501eb3e1003d5cda4d47f54321d81d678c26981e7aJohn McCall
3511eb3e1003d5cda4d47f54321d81d678c26981e7aJohn McCall  struct NonConstArray {
3521eb3e1003d5cda4d47f54321d81d678c26981e7aJohn McCall    int operator[](unsigned); // expected-note {{candidate}}
3531eb3e1003d5cda4d47f54321d81d678c26981e7aJohn McCall  };
3541eb3e1003d5cda4d47f54321d81d678c26981e7aJohn McCall  int test1() {
3559db7dbb918ca49f4ee6c181e4917e7b6ec547353Douglas Gregor    const NonConstArray x = NonConstArray();
3561eb3e1003d5cda4d47f54321d81d678c26981e7aJohn McCall    return x[0]; // expected-error {{no viable overloaded operator[] for type}}
3571eb3e1003d5cda4d47f54321d81d678c26981e7aJohn McCall  }
3581eb3e1003d5cda4d47f54321d81d678c26981e7aJohn McCall
3591eb3e1003d5cda4d47f54321d81d678c26981e7aJohn McCall  // Not really part of this PR, but implemented at the same time.
3601eb3e1003d5cda4d47f54321d81d678c26981e7aJohn McCall  struct NotAFunction {};
3611eb3e1003d5cda4d47f54321d81d678c26981e7aJohn McCall  void test2() {
3621eb3e1003d5cda4d47f54321d81d678c26981e7aJohn McCall    NotAFunction x;
3631eb3e1003d5cda4d47f54321d81d678c26981e7aJohn McCall    x(); // expected-error {{does not provide a call operator}}
3641eb3e1003d5cda4d47f54321d81d678c26981e7aJohn McCall  }
3651eb3e1003d5cda4d47f54321d81d678c26981e7aJohn McCall}
3666bf356fb8f769575d5e6e54a3bf81436ddec106aDouglas Gregor
3676bf356fb8f769575d5e6e54a3bf81436ddec106aDouglas Gregor// Operator lookup through using declarations.
3686bf356fb8f769575d5e6e54a3bf81436ddec106aDouglas Gregornamespace N {
3696bf356fb8f769575d5e6e54a3bf81436ddec106aDouglas Gregor  struct X2 { };
3706bf356fb8f769575d5e6e54a3bf81436ddec106aDouglas Gregor}
3716bf356fb8f769575d5e6e54a3bf81436ddec106aDouglas Gregor
3726bf356fb8f769575d5e6e54a3bf81436ddec106aDouglas Gregornamespace N2 {
3736bf356fb8f769575d5e6e54a3bf81436ddec106aDouglas Gregor  namespace M {
3746bf356fb8f769575d5e6e54a3bf81436ddec106aDouglas Gregor    namespace Inner {
3756bf356fb8f769575d5e6e54a3bf81436ddec106aDouglas Gregor      template<typename T>
3766bf356fb8f769575d5e6e54a3bf81436ddec106aDouglas Gregor      N::X2 &operator<<(N::X2&, const T&);
3776bf356fb8f769575d5e6e54a3bf81436ddec106aDouglas Gregor    }
3786bf356fb8f769575d5e6e54a3bf81436ddec106aDouglas Gregor    using Inner::operator<<;
3796bf356fb8f769575d5e6e54a3bf81436ddec106aDouglas Gregor  }
3806bf356fb8f769575d5e6e54a3bf81436ddec106aDouglas Gregor}
3816bf356fb8f769575d5e6e54a3bf81436ddec106aDouglas Gregor
3826bf356fb8f769575d5e6e54a3bf81436ddec106aDouglas Gregorvoid test_lookup_through_using() {
3836bf356fb8f769575d5e6e54a3bf81436ddec106aDouglas Gregor  using namespace N2::M;
3846bf356fb8f769575d5e6e54a3bf81436ddec106aDouglas Gregor  N::X2 x;
3856bf356fb8f769575d5e6e54a3bf81436ddec106aDouglas Gregor  x << 17;
3866bf356fb8f769575d5e6e54a3bf81436ddec106aDouglas Gregor}
38760b3e38d421cab497de1c62c06be6a6a5f321edfDouglas Gregor
38860b3e38d421cab497de1c62c06be6a6a5f321edfDouglas Gregornamespace rdar9136502 {
38960b3e38d421cab497de1c62c06be6a6a5f321edfDouglas Gregor  struct X {
390864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    int i();
391864c041e118155c2b1ce0ba36942a3da5a4a055eJohn McCall    int i(int);
39260b3e38d421cab497de1c62c06be6a6a5f321edfDouglas Gregor  };
39360b3e38d421cab497de1c62c06be6a6a5f321edfDouglas Gregor
39460b3e38d421cab497de1c62c06be6a6a5f321edfDouglas Gregor  struct Y {
3955acb0c98b363400f6ade0ae7250f0102224e806bJohn McCall    Y &operator<<(int);
39660b3e38d421cab497de1c62c06be6a6a5f321edfDouglas Gregor  };
39760b3e38d421cab497de1c62c06be6a6a5f321edfDouglas Gregor
39860b3e38d421cab497de1c62c06be6a6a5f321edfDouglas Gregor  void f(X x, Y y) {
3996dbba4fc128e2e2f5b26be996392bd32c0707f13John McCall    y << x.i; // expected-error{{reference to non-static member function must be called}}
40060b3e38d421cab497de1c62c06be6a6a5f321edfDouglas Gregor  }
40160b3e38d421cab497de1c62c06be6a6a5f321edfDouglas Gregor}
402439d3c3d76f858df5f25239f2a70f04312eacb5bDouglas Gregor
403439d3c3d76f858df5f25239f2a70f04312eacb5bDouglas Gregornamespace rdar9222009 {
404439d3c3d76f858df5f25239f2a70f04312eacb5bDouglas Gregorclass StringRef {
405439d3c3d76f858df5f25239f2a70f04312eacb5bDouglas Gregor  inline bool operator==(StringRef LHS, StringRef RHS) { // expected-error{{overloaded 'operator==' must be a binary operator (has 3 parameters)}}
406439d3c3d76f858df5f25239f2a70f04312eacb5bDouglas Gregor    return !(LHS == RHS); // expected-error{{invalid operands to binary expression ('rdar9222009::StringRef' and 'rdar9222009::StringRef')}}
407439d3c3d76f858df5f25239f2a70f04312eacb5bDouglas Gregor  }
408439d3c3d76f858df5f25239f2a70f04312eacb5bDouglas Gregor};
409439d3c3d76f858df5f25239f2a70f04312eacb5bDouglas Gregor
410439d3c3d76f858df5f25239f2a70f04312eacb5bDouglas Gregor}
411