2012-11-29 13:41:51 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -fshow-overloads=best -verify -triple x86_64-linux-gnu %s
|
2015-11-18 04:25:05 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -fshow-overloads=best -verify -triple x86_64-linux-gnu -std=c++98 %s
|
|
|
|
// RUN: %clang_cc1 -fsyntax-only -fshow-overloads=best -verify -triple x86_64-linux-gnu -std=c++11 %s
|
2012-09-12 18:45:40 +08:00
|
|
|
|
Implement support for operator overloading using candidate operator
functions for built-in operators, e.g., the builtin
bool operator==(int const*, int const*)
can be used for the expression "x1 == x2" given:
struct X {
operator int const*();
} x1, x2;
The scheme for handling these built-in operators is relatively simple:
for each candidate required by the standard, create a special kind of
candidate function for the built-in. If overload resolution picks the
built-in operator, we perform the appropriate conversions on the
arguments and then let the normal built-in operator take care of it.
There may be some optimization opportunity left: if we can reduce the
number of built-in operator overloads we generate, overload resolution
for these cases will go faster. However, one must be careful when
doing this: GCC generates too few operator overloads in our little
test program, and fails to compile it because none of the overloads it
generates match.
Note that we only support operator overload for non-member binary
operators at the moment. The other operators will follow.
As part of this change, ImplicitCastExpr can now be an lvalue.
llvm-svn: 59148
2008-11-13 01:17:38 +08:00
|
|
|
struct yes;
|
|
|
|
struct no;
|
|
|
|
|
|
|
|
struct Short {
|
|
|
|
operator short();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Long {
|
|
|
|
operator long();
|
|
|
|
};
|
|
|
|
|
2008-11-19 11:25:36 +08:00
|
|
|
enum E1 { };
|
|
|
|
struct Enum1 {
|
|
|
|
operator E1();
|
|
|
|
};
|
|
|
|
|
|
|
|
enum E2 { };
|
|
|
|
struct Enum2 {
|
|
|
|
operator E2();
|
|
|
|
};
|
|
|
|
|
2009-08-25 01:42:35 +08:00
|
|
|
|
|
|
|
struct X {
|
|
|
|
void f();
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef void (X::*pmf)();
|
|
|
|
struct Xpmf {
|
|
|
|
operator pmf();
|
|
|
|
};
|
|
|
|
|
Implement support for operator overloading using candidate operator
functions for built-in operators, e.g., the builtin
bool operator==(int const*, int const*)
can be used for the expression "x1 == x2" given:
struct X {
operator int const*();
} x1, x2;
The scheme for handling these built-in operators is relatively simple:
for each candidate required by the standard, create a special kind of
candidate function for the built-in. If overload resolution picks the
built-in operator, we perform the appropriate conversions on the
arguments and then let the normal built-in operator take care of it.
There may be some optimization opportunity left: if we can reduce the
number of built-in operator overloads we generate, overload resolution
for these cases will go faster. However, one must be careful when
doing this: GCC generates too few operator overloads in our little
test program, and fails to compile it because none of the overloads it
generates match.
Note that we only support operator overload for non-member binary
operators at the moment. The other operators will follow.
As part of this change, ImplicitCastExpr can now be an lvalue.
llvm-svn: 59148
2008-11-13 01:17:38 +08:00
|
|
|
yes& islong(long);
|
2008-11-19 11:25:36 +08:00
|
|
|
yes& islong(unsigned long); // FIXME: shouldn't be needed
|
Implement support for operator overloading using candidate operator
functions for built-in operators, e.g., the builtin
bool operator==(int const*, int const*)
can be used for the expression "x1 == x2" given:
struct X {
operator int const*();
} x1, x2;
The scheme for handling these built-in operators is relatively simple:
for each candidate required by the standard, create a special kind of
candidate function for the built-in. If overload resolution picks the
built-in operator, we perform the appropriate conversions on the
arguments and then let the normal built-in operator take care of it.
There may be some optimization opportunity left: if we can reduce the
number of built-in operator overloads we generate, overload resolution
for these cases will go faster. However, one must be careful when
doing this: GCC generates too few operator overloads in our little
test program, and fails to compile it because none of the overloads it
generates match.
Note that we only support operator overload for non-member binary
operators at the moment. The other operators will follow.
As part of this change, ImplicitCastExpr can now be an lvalue.
llvm-svn: 59148
2008-11-13 01:17:38 +08:00
|
|
|
no& islong(int);
|
|
|
|
|
2009-08-25 01:42:35 +08:00
|
|
|
void f(Short s, Long l, Enum1 e1, Enum2 e2, Xpmf pmf) {
|
2008-11-19 23:42:04 +08:00
|
|
|
// C++ [over.built]p8
|
|
|
|
int i1 = +e1;
|
|
|
|
int i2 = -e2;
|
|
|
|
|
|
|
|
// C++ [over.built]p10:
|
|
|
|
int i3 = ~s;
|
|
|
|
bool b1 = !s;
|
|
|
|
|
Implement support for operator overloading using candidate operator
functions for built-in operators, e.g., the builtin
bool operator==(int const*, int const*)
can be used for the expression "x1 == x2" given:
struct X {
operator int const*();
} x1, x2;
The scheme for handling these built-in operators is relatively simple:
for each candidate required by the standard, create a special kind of
candidate function for the built-in. If overload resolution picks the
built-in operator, we perform the appropriate conversions on the
arguments and then let the normal built-in operator take care of it.
There may be some optimization opportunity left: if we can reduce the
number of built-in operator overloads we generate, overload resolution
for these cases will go faster. However, one must be careful when
doing this: GCC generates too few operator overloads in our little
test program, and fails to compile it because none of the overloads it
generates match.
Note that we only support operator overload for non-member binary
operators at the moment. The other operators will follow.
As part of this change, ImplicitCastExpr can now be an lvalue.
llvm-svn: 59148
2008-11-13 01:17:38 +08:00
|
|
|
// C++ [over.built]p12
|
|
|
|
(void)static_cast<yes&>(islong(s + l));
|
|
|
|
(void)static_cast<no&>(islong(s + s));
|
|
|
|
|
2009-08-25 01:42:35 +08:00
|
|
|
// C++ [over.built]p16
|
|
|
|
(void)(pmf == &X::f);
|
|
|
|
(void)(pmf == 0);
|
|
|
|
|
Implement support for operator overloading using candidate operator
functions for built-in operators, e.g., the builtin
bool operator==(int const*, int const*)
can be used for the expression "x1 == x2" given:
struct X {
operator int const*();
} x1, x2;
The scheme for handling these built-in operators is relatively simple:
for each candidate required by the standard, create a special kind of
candidate function for the built-in. If overload resolution picks the
built-in operator, we perform the appropriate conversions on the
arguments and then let the normal built-in operator take care of it.
There may be some optimization opportunity left: if we can reduce the
number of built-in operator overloads we generate, overload resolution
for these cases will go faster. However, one must be careful when
doing this: GCC generates too few operator overloads in our little
test program, and fails to compile it because none of the overloads it
generates match.
Note that we only support operator overload for non-member binary
operators at the moment. The other operators will follow.
As part of this change, ImplicitCastExpr can now be an lvalue.
llvm-svn: 59148
2008-11-13 01:17:38 +08:00
|
|
|
// C++ [over.built]p17
|
|
|
|
(void)static_cast<yes&>(islong(s % l));
|
|
|
|
(void)static_cast<yes&>(islong(l << s));
|
|
|
|
(void)static_cast<no&>(islong(s << l));
|
2008-11-19 11:25:36 +08:00
|
|
|
(void)static_cast<yes&>(islong(e1 % l));
|
|
|
|
// FIXME: should pass (void)static_cast<no&>(islong(e1 % e2));
|
Implement support for operator overloading using candidate operator
functions for built-in operators, e.g., the builtin
bool operator==(int const*, int const*)
can be used for the expression "x1 == x2" given:
struct X {
operator int const*();
} x1, x2;
The scheme for handling these built-in operators is relatively simple:
for each candidate required by the standard, create a special kind of
candidate function for the built-in. If overload resolution picks the
built-in operator, we perform the appropriate conversions on the
arguments and then let the normal built-in operator take care of it.
There may be some optimization opportunity left: if we can reduce the
number of built-in operator overloads we generate, overload resolution
for these cases will go faster. However, one must be careful when
doing this: GCC generates too few operator overloads in our little
test program, and fails to compile it because none of the overloads it
generates match.
Note that we only support operator overload for non-member binary
operators at the moment. The other operators will follow.
As part of this change, ImplicitCastExpr can now be an lvalue.
llvm-svn: 59148
2008-11-13 01:17:38 +08:00
|
|
|
}
|
|
|
|
|
2015-11-18 04:25:05 +08:00
|
|
|
struct ShortRef { // expected-note{{candidate function (the implicit copy assignment operator) not viable}}
|
|
|
|
#if __cplusplus >= 201103L // C++11 or later
|
|
|
|
// expected-note@-2 {{candidate function (the implicit move assignment operator) not viable}}
|
|
|
|
#endif
|
Implement support for operator overloading using candidate operator
functions for built-in operators, e.g., the builtin
bool operator==(int const*, int const*)
can be used for the expression "x1 == x2" given:
struct X {
operator int const*();
} x1, x2;
The scheme for handling these built-in operators is relatively simple:
for each candidate required by the standard, create a special kind of
candidate function for the built-in. If overload resolution picks the
built-in operator, we perform the appropriate conversions on the
arguments and then let the normal built-in operator take care of it.
There may be some optimization opportunity left: if we can reduce the
number of built-in operator overloads we generate, overload resolution
for these cases will go faster. However, one must be careful when
doing this: GCC generates too few operator overloads in our little
test program, and fails to compile it because none of the overloads it
generates match.
Note that we only support operator overload for non-member binary
operators at the moment. The other operators will follow.
As part of this change, ImplicitCastExpr can now be an lvalue.
llvm-svn: 59148
2008-11-13 01:17:38 +08:00
|
|
|
operator short&();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LongRef {
|
|
|
|
operator volatile long&();
|
|
|
|
};
|
|
|
|
|
2015-11-18 04:25:05 +08:00
|
|
|
struct XpmfRef { // expected-note{{candidate function (the implicit copy assignment operator) not viable}}
|
|
|
|
#if __cplusplus >= 201103L // C++11 or later
|
|
|
|
// expected-note@-2 {{candidate function (the implicit move assignment operator) not viable}}
|
|
|
|
#endif
|
2009-08-25 01:42:35 +08:00
|
|
|
operator pmf&();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct E2Ref {
|
|
|
|
operator E2&();
|
|
|
|
};
|
|
|
|
|
|
|
|
void g(ShortRef sr, LongRef lr, E2Ref e2_ref, XpmfRef pmf_ref) {
|
2008-11-19 23:42:04 +08:00
|
|
|
// C++ [over.built]p3
|
|
|
|
short s1 = sr++;
|
|
|
|
|
|
|
|
// C++ [over.built]p3
|
|
|
|
long l1 = lr--;
|
|
|
|
|
Implement support for operator overloading using candidate operator
functions for built-in operators, e.g., the builtin
bool operator==(int const*, int const*)
can be used for the expression "x1 == x2" given:
struct X {
operator int const*();
} x1, x2;
The scheme for handling these built-in operators is relatively simple:
for each candidate required by the standard, create a special kind of
candidate function for the built-in. If overload resolution picks the
built-in operator, we perform the appropriate conversions on the
arguments and then let the normal built-in operator take care of it.
There may be some optimization opportunity left: if we can reduce the
number of built-in operator overloads we generate, overload resolution
for these cases will go faster. However, one must be careful when
doing this: GCC generates too few operator overloads in our little
test program, and fails to compile it because none of the overloads it
generates match.
Note that we only support operator overload for non-member binary
operators at the moment. The other operators will follow.
As part of this change, ImplicitCastExpr can now be an lvalue.
llvm-svn: 59148
2008-11-13 01:17:38 +08:00
|
|
|
// C++ [over.built]p18
|
|
|
|
short& sr1 = (sr *= lr);
|
|
|
|
volatile long& lr1 = (lr *= sr);
|
|
|
|
|
2009-08-25 01:42:35 +08:00
|
|
|
// C++ [over.built]p20:
|
|
|
|
E2 e2r2;
|
|
|
|
e2r2 = e2_ref;
|
|
|
|
|
|
|
|
pmf &pmr = (pmf_ref = &X::f); // expected-error{{no viable overloaded '='}}
|
|
|
|
pmf pmr2;
|
|
|
|
pmr2 = pmf_ref;
|
|
|
|
|
Implement support for operator overloading using candidate operator
functions for built-in operators, e.g., the builtin
bool operator==(int const*, int const*)
can be used for the expression "x1 == x2" given:
struct X {
operator int const*();
} x1, x2;
The scheme for handling these built-in operators is relatively simple:
for each candidate required by the standard, create a special kind of
candidate function for the built-in. If overload resolution picks the
built-in operator, we perform the appropriate conversions on the
arguments and then let the normal built-in operator take care of it.
There may be some optimization opportunity left: if we can reduce the
number of built-in operator overloads we generate, overload resolution
for these cases will go faster. However, one must be careful when
doing this: GCC generates too few operator overloads in our little
test program, and fails to compile it because none of the overloads it
generates match.
Note that we only support operator overload for non-member binary
operators at the moment. The other operators will follow.
As part of this change, ImplicitCastExpr can now be an lvalue.
llvm-svn: 59148
2008-11-13 01:17:38 +08:00
|
|
|
// C++ [over.built]p22
|
|
|
|
short& sr2 = (sr %= lr);
|
|
|
|
volatile long& lr2 = (lr <<= sr);
|
|
|
|
|
|
|
|
bool b1 = (sr && lr) || (sr || lr);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct VolatileIntPtr {
|
|
|
|
operator int volatile *();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ConstIntPtr {
|
|
|
|
operator int const *();
|
|
|
|
};
|
|
|
|
|
2008-11-19 23:42:04 +08:00
|
|
|
struct VolatileIntPtrRef {
|
|
|
|
operator int volatile *&();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ConstIntPtrRef {
|
|
|
|
operator int const *&();
|
|
|
|
};
|
|
|
|
|
|
|
|
void test_with_ptrs(VolatileIntPtr vip, ConstIntPtr cip, ShortRef sr,
|
|
|
|
VolatileIntPtrRef vipr, ConstIntPtrRef cipr) {
|
Implement support for operator overloading using candidate operator
functions for built-in operators, e.g., the builtin
bool operator==(int const*, int const*)
can be used for the expression "x1 == x2" given:
struct X {
operator int const*();
} x1, x2;
The scheme for handling these built-in operators is relatively simple:
for each candidate required by the standard, create a special kind of
candidate function for the built-in. If overload resolution picks the
built-in operator, we perform the appropriate conversions on the
arguments and then let the normal built-in operator take care of it.
There may be some optimization opportunity left: if we can reduce the
number of built-in operator overloads we generate, overload resolution
for these cases will go faster. However, one must be careful when
doing this: GCC generates too few operator overloads in our little
test program, and fails to compile it because none of the overloads it
generates match.
Note that we only support operator overload for non-member binary
operators at the moment. The other operators will follow.
As part of this change, ImplicitCastExpr can now be an lvalue.
llvm-svn: 59148
2008-11-13 01:17:38 +08:00
|
|
|
const int& cir1 = cip[sr];
|
|
|
|
const int& cir2 = sr[cip];
|
|
|
|
volatile int& vir1 = vip[sr];
|
|
|
|
volatile int& vir2 = sr[vip];
|
|
|
|
bool b1 = (vip == cip);
|
|
|
|
long p1 = vip - cip;
|
2008-11-19 23:42:04 +08:00
|
|
|
|
|
|
|
// C++ [over.built]p5:
|
|
|
|
int volatile *vip1 = vipr++;
|
|
|
|
int const *cip1 = cipr++;
|
|
|
|
int volatile *&vipr1 = ++vipr;
|
|
|
|
int const *&cipr1 = --cipr;
|
|
|
|
|
|
|
|
// C++ [over.built]p6:
|
|
|
|
int volatile &ivr = *vip;
|
|
|
|
|
|
|
|
// C++ [over.built]p8:
|
|
|
|
int volatile *vip2 = +vip;
|
|
|
|
int i1 = +sr;
|
|
|
|
int i2 = -sr;
|
2008-11-20 01:17:41 +08:00
|
|
|
|
|
|
|
// C++ [over.built]p13:
|
|
|
|
int volatile &ivr2 = vip[17];
|
|
|
|
int const &icr2 = 17[cip];
|
Implement support for operator overloading using candidate operator
functions for built-in operators, e.g., the builtin
bool operator==(int const*, int const*)
can be used for the expression "x1 == x2" given:
struct X {
operator int const*();
} x1, x2;
The scheme for handling these built-in operators is relatively simple:
for each candidate required by the standard, create a special kind of
candidate function for the built-in. If overload resolution picks the
built-in operator, we perform the appropriate conversions on the
arguments and then let the normal built-in operator take care of it.
There may be some optimization opportunity left: if we can reduce the
number of built-in operator overloads we generate, overload resolution
for these cases will go faster. However, one must be careful when
doing this: GCC generates too few operator overloads in our little
test program, and fails to compile it because none of the overloads it
generates match.
Note that we only support operator overload for non-member binary
operators at the moment. The other operators will follow.
As part of this change, ImplicitCastExpr can now be an lvalue.
llvm-svn: 59148
2008-11-13 01:17:38 +08:00
|
|
|
}
|
2008-11-19 23:42:04 +08:00
|
|
|
|
2009-01-13 08:52:54 +08:00
|
|
|
// C++ [over.match.open]p4
|
|
|
|
|
|
|
|
void test_assign_restrictions(ShortRef& sr) {
|
2009-05-21 19:50:50 +08:00
|
|
|
sr = (short)0; // expected-error{{no viable overloaded '='}}
|
2009-01-13 08:52:54 +08:00
|
|
|
}
|
2009-10-22 06:01:30 +08:00
|
|
|
|
|
|
|
struct Base { };
|
|
|
|
struct Derived1 : Base { };
|
|
|
|
struct Derived2 : Base { };
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct ConvertibleToPtrOf {
|
|
|
|
operator T*();
|
|
|
|
};
|
|
|
|
|
|
|
|
bool test_with_base_ptrs(ConvertibleToPtrOf<Derived1> d1,
|
|
|
|
ConvertibleToPtrOf<Derived2> d2) {
|
|
|
|
return d1 == d2; // expected-error{{invalid operands}}
|
|
|
|
}
|
|
|
|
|
|
|
|
// DR425
|
|
|
|
struct A {
|
|
|
|
template< typename T > operator T() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
void test_dr425(A a) {
|
|
|
|
// FIXME: lots of candidates here!
|
|
|
|
(void)(1.0f * a); // expected-error{{ambiguous}} \
|
2010-06-11 13:57:47 +08:00
|
|
|
// expected-note 4{{candidate}} \
|
2016-04-16 02:04:13 +08:00
|
|
|
// expected-note {{remaining 117 candidates omitted; pass -fshow-overloads=all to show them}}
|
2009-10-22 06:01:30 +08:00
|
|
|
}
|
2009-11-10 05:02:05 +08:00
|
|
|
|
|
|
|
// pr5432
|
|
|
|
enum e {X};
|
|
|
|
|
|
|
|
const int a[][2] = {{1}};
|
|
|
|
|
|
|
|
int test_pr5432() {
|
|
|
|
return a[X][X];
|
|
|
|
}
|
|
|
|
|
2009-11-15 05:26:41 +08:00
|
|
|
void f() {
|
|
|
|
(void)__extension__(A());
|
|
|
|
}
|
2010-06-09 05:03:17 +08:00
|
|
|
|
|
|
|
namespace PR7319 {
|
|
|
|
typedef enum { Enum1, Enum2, Enum3 } MyEnum;
|
|
|
|
|
|
|
|
template<typename X> bool operator>(const X &inX1, const X &inX2);
|
|
|
|
|
|
|
|
void f() {
|
|
|
|
MyEnum e1, e2;
|
|
|
|
if (e1 > e2) {}
|
|
|
|
}
|
|
|
|
}
|
2010-11-04 01:00:07 +08:00
|
|
|
|
|
|
|
namespace PR8477 {
|
|
|
|
struct Foo {
|
|
|
|
operator bool();
|
|
|
|
operator const char *();
|
|
|
|
};
|
|
|
|
|
|
|
|
bool doit() {
|
|
|
|
Foo foo;
|
|
|
|
long long zero = 0;
|
|
|
|
(void)(foo + zero);
|
|
|
|
(void)(foo - zero);
|
|
|
|
(void)(zero + foo);
|
|
|
|
(void)(zero[foo]);
|
|
|
|
(void)(foo - foo); // expected-error{{use of overloaded operator '-' is ambiguous}} \
|
|
|
|
// expected-note 4{{built-in candidate operator-}} \
|
|
|
|
// expected-note{{candidates omitted}}
|
|
|
|
return foo[zero] == zero;
|
|
|
|
}
|
|
|
|
}
|
2011-01-05 08:13:17 +08:00
|
|
|
|
|
|
|
namespace PR7851 {
|
|
|
|
struct X {
|
|
|
|
operator const void *() const;
|
|
|
|
operator void *();
|
|
|
|
|
|
|
|
operator const unsigned *() const;
|
|
|
|
operator unsigned *();
|
|
|
|
};
|
|
|
|
|
|
|
|
void f() {
|
|
|
|
X x;
|
|
|
|
x[0] = 1;
|
|
|
|
*x = 0;
|
|
|
|
(void)(x - x);
|
|
|
|
}
|
|
|
|
}
|
2012-06-04 08:15:09 +08:00
|
|
|
|
|
|
|
namespace PR12854 {
|
|
|
|
enum { size = 1 };
|
|
|
|
void plus_equals() {
|
|
|
|
int* __restrict py;
|
|
|
|
py += size;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct RestrictInt {
|
|
|
|
operator int* __restrict &();
|
|
|
|
};
|
|
|
|
|
|
|
|
void user_conversions(RestrictInt ri) {
|
|
|
|
++ri;
|
|
|
|
--ri;
|
|
|
|
ri++;
|
|
|
|
ri--;
|
|
|
|
}
|
|
|
|
}
|
2012-06-10 16:00:26 +08:00
|
|
|
|
|
|
|
namespace PR12964 {
|
|
|
|
struct X { operator __int128() const; } x;
|
|
|
|
bool a = x == __int128(0);
|
|
|
|
bool b = x == 0;
|
|
|
|
|
|
|
|
struct Y { operator unsigned __int128() const; } y;
|
|
|
|
bool c = y == __int128(0);
|
|
|
|
bool d = y == 0;
|
|
|
|
|
|
|
|
bool e = x == y;
|
|
|
|
}
|