2013-07-12 07:55:07 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
|
2008-11-07 07:29:22 +08:00
|
|
|
class X { };
|
|
|
|
|
|
|
|
X operator+(X, X);
|
|
|
|
|
|
|
|
void f(X x) {
|
|
|
|
x = x + x;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Y;
|
|
|
|
struct Z;
|
|
|
|
|
|
|
|
struct Y {
|
|
|
|
Y(const Z&);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Z {
|
|
|
|
Z(const Y&);
|
|
|
|
};
|
|
|
|
|
|
|
|
Y operator+(Y, Y);
|
|
|
|
bool operator-(Y, Y); // expected-note{{candidate function}}
|
|
|
|
bool operator-(Z, Z); // expected-note{{candidate function}}
|
|
|
|
|
|
|
|
void g(Y y, Z z) {
|
|
|
|
y = y + z;
|
2010-11-14 04:06:38 +08:00
|
|
|
bool b = y - z; // expected-error{{use of overloaded operator '-' is ambiguous}}
|
2008-11-07 07:29:22 +08:00
|
|
|
}
|
|
|
|
|
2008-11-19 07:14:02 +08:00
|
|
|
struct A {
|
2009-10-01 05:46:01 +08:00
|
|
|
bool operator==(Z&); // expected-note 2{{candidate function}}
|
2008-11-19 07:14:02 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
A make_A();
|
2008-11-07 07:29:22 +08:00
|
|
|
|
2011-05-05 08:13:13 +08:00
|
|
|
bool operator==(A&, Z&); // expected-note 3{{candidate function}}
|
2008-11-19 07:14:02 +08:00
|
|
|
|
|
|
|
void h(A a, const A ac, Z z) {
|
2011-08-17 17:49:44 +08:00
|
|
|
make_A() == z; // expected-warning{{equality comparison result unused}}
|
2010-11-14 04:06:38 +08:00
|
|
|
a == z; // expected-error{{use of overloaded operator '==' is ambiguous}}
|
2010-09-05 08:17:29 +08:00
|
|
|
ac == z; // expected-error{{invalid operands to binary expression ('const A' and 'Z')}}
|
2008-11-19 07:14:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct B {
|
|
|
|
bool operator==(const B&) const;
|
|
|
|
|
|
|
|
void test(Z z) {
|
2011-08-17 17:49:44 +08:00
|
|
|
make_A() == z; // expected-warning{{equality comparison result unused}}
|
2008-11-19 07:14:02 +08:00
|
|
|
}
|
|
|
|
};
|
2008-11-19 11:25:36 +08:00
|
|
|
|
2010-06-09 03:50:34 +08:00
|
|
|
// we shouldn't see warnings about self-comparison,
|
|
|
|
// this is a member function, we dunno what it'll do
|
|
|
|
bool i(B b)
|
|
|
|
{
|
|
|
|
return b == b;
|
|
|
|
}
|
|
|
|
|
2008-11-19 11:25:36 +08:00
|
|
|
enum Enum1 { };
|
|
|
|
enum Enum2 { };
|
|
|
|
|
|
|
|
struct E1 {
|
|
|
|
E1(Enum1) { }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct E2 {
|
|
|
|
E2(Enum2);
|
|
|
|
};
|
|
|
|
|
|
|
|
// C++ [over.match.oper]p3 - enum restriction.
|
2011-05-05 08:13:13 +08:00
|
|
|
float& operator==(E1, E2); // expected-note{{candidate function}}
|
2008-11-19 11:25:36 +08:00
|
|
|
|
2011-02-17 16:37:06 +08:00
|
|
|
void enum_test(Enum1 enum1, Enum2 enum2, E1 e1, E2 e2, Enum1 next_enum1) {
|
2008-11-19 11:25:36 +08:00
|
|
|
float &f1 = (e1 == e2);
|
|
|
|
float &f2 = (enum1 == e2);
|
|
|
|
float &f3 = (e1 == enum2);
|
2011-02-17 16:37:06 +08:00
|
|
|
float &f4 = (enum1 == next_enum1); // expected-error{{non-const lvalue reference to type 'float' cannot bind to a temporary of type 'bool'}}
|
2008-11-19 11:25:36 +08:00
|
|
|
}
|
2008-11-19 23:42:04 +08:00
|
|
|
|
2009-10-24 03:23:15 +08:00
|
|
|
// PR5244 - Argument-dependent lookup would include the two operators below,
|
|
|
|
// which would break later assumptions and lead to a crash.
|
|
|
|
class pr5244_foo
|
|
|
|
{
|
|
|
|
pr5244_foo(int);
|
|
|
|
pr5244_foo(char);
|
|
|
|
};
|
|
|
|
|
2011-05-05 08:13:13 +08:00
|
|
|
bool operator==(const pr5244_foo& s1, const pr5244_foo& s2); // expected-note{{candidate function}}
|
|
|
|
bool operator==(char c, const pr5244_foo& s); // expected-note{{candidate function}}
|
2009-10-24 03:23:15 +08:00
|
|
|
|
|
|
|
enum pr5244_bar
|
|
|
|
{
|
|
|
|
pr5244_BAR
|
|
|
|
};
|
|
|
|
|
|
|
|
class pr5244_baz
|
|
|
|
{
|
2010-04-10 03:03:51 +08:00
|
|
|
public:
|
2009-10-24 03:23:15 +08:00
|
|
|
pr5244_bar quux;
|
|
|
|
};
|
|
|
|
|
|
|
|
void pr5244_barbaz()
|
|
|
|
{
|
|
|
|
pr5244_baz quuux;
|
|
|
|
(void)(pr5244_BAR == quuux.quux);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-19 23:42:04 +08:00
|
|
|
|
|
|
|
struct PostInc {
|
|
|
|
PostInc operator++(int);
|
|
|
|
PostInc& operator++();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PostDec {
|
|
|
|
PostDec operator--(int);
|
|
|
|
PostDec& operator--();
|
|
|
|
};
|
|
|
|
|
|
|
|
void incdec_test(PostInc pi, PostDec pd) {
|
|
|
|
const PostInc& pi1 = pi++;
|
|
|
|
const PostDec& pd1 = pd--;
|
|
|
|
PostInc &pi2 = ++pi;
|
|
|
|
PostDec &pd2 = --pd;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SmartPtr {
|
|
|
|
int& operator*();
|
2008-11-21 23:36:28 +08:00
|
|
|
long& operator*() const volatile;
|
2008-11-19 23:42:04 +08:00
|
|
|
};
|
|
|
|
|
2008-11-21 23:36:28 +08:00
|
|
|
void test_smartptr(SmartPtr ptr, const SmartPtr cptr,
|
|
|
|
const volatile SmartPtr cvptr) {
|
2008-11-19 23:42:04 +08:00
|
|
|
int &ir = *ptr;
|
2008-11-21 23:36:28 +08:00
|
|
|
long &lr = *cptr;
|
|
|
|
long &lr2 = *cvptr;
|
2008-11-19 23:42:04 +08:00
|
|
|
}
|
2008-11-20 01:17:41 +08:00
|
|
|
|
|
|
|
|
|
|
|
struct ArrayLike {
|
|
|
|
int& operator[](int);
|
|
|
|
};
|
|
|
|
|
|
|
|
void test_arraylike(ArrayLike a) {
|
|
|
|
int& ir = a[17];
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SmartRef {
|
|
|
|
int* operator&();
|
|
|
|
};
|
|
|
|
|
|
|
|
void test_smartref(SmartRef r) {
|
|
|
|
int* ip = &r;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool& operator,(X, Y);
|
|
|
|
|
|
|
|
void test_comma(X x, Y y) {
|
|
|
|
bool& b1 = (x, y);
|
2010-09-20 07:03:35 +08:00
|
|
|
X& xr = (x, x); // expected-warning {{expression result unused}}
|
2008-11-20 01:17:41 +08:00
|
|
|
}
|
2008-11-20 05:05:33 +08:00
|
|
|
|
|
|
|
struct Callable {
|
|
|
|
int& operator()(int, double = 2.71828); // expected-note{{candidate function}}
|
|
|
|
float& operator()(int, double, long, ...); // expected-note{{candidate function}}
|
2009-01-13 13:10:00 +08:00
|
|
|
|
|
|
|
double& operator()(float); // expected-note{{candidate function}}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Callable2 {
|
|
|
|
int& operator()(int i = 0);
|
|
|
|
double& operator()(...) const;
|
2008-11-20 05:05:33 +08:00
|
|
|
};
|
|
|
|
|
2009-11-15 15:48:03 +08:00
|
|
|
struct DerivesCallable : public Callable {
|
|
|
|
};
|
|
|
|
|
|
|
|
void test_callable(Callable c, Callable2 c2, const Callable2& c2c,
|
|
|
|
DerivesCallable dc) {
|
2008-11-20 05:05:33 +08:00
|
|
|
int &ir = c(1);
|
|
|
|
float &fr = c(1, 3.14159, 17, 42);
|
|
|
|
|
2010-03-10 19:27:22 +08:00
|
|
|
c(); // expected-error{{no matching function for call to object of type 'Callable'}}
|
2009-01-13 13:10:00 +08:00
|
|
|
|
|
|
|
double &dr = c(1.0f);
|
|
|
|
|
|
|
|
int &ir2 = c2();
|
|
|
|
int &ir3 = c2(1);
|
|
|
|
double &fr2 = c2c();
|
2009-11-15 15:48:03 +08:00
|
|
|
|
|
|
|
int &ir4 = dc(17);
|
|
|
|
double &fr3 = dc(3.14159f);
|
2008-11-20 05:05:33 +08:00
|
|
|
}
|
2008-11-20 06:57:39 +08:00
|
|
|
|
2008-11-21 10:54:28 +08:00
|
|
|
typedef float FLOAT;
|
|
|
|
typedef int& INTREF;
|
|
|
|
typedef INTREF Func1(FLOAT, double);
|
2008-11-20 06:57:39 +08:00
|
|
|
typedef float& Func2(int, double);
|
|
|
|
|
|
|
|
struct ConvertToFunc {
|
2010-01-12 03:36:35 +08:00
|
|
|
operator Func1*(); // expected-note 2{{conversion candidate of type 'INTREF (*)(FLOAT, double)'}}
|
|
|
|
operator Func2&(); // expected-note 2{{conversion candidate of type 'float &(&)(int, double)'}}
|
2008-11-20 06:59:19 +08:00
|
|
|
void operator()();
|
2008-11-20 06:57:39 +08:00
|
|
|
};
|
|
|
|
|
2010-01-12 03:36:35 +08:00
|
|
|
struct ConvertToFuncDerived : ConvertToFunc { };
|
|
|
|
|
|
|
|
void test_funcptr_call(ConvertToFunc ctf, ConvertToFuncDerived ctfd) {
|
2008-11-20 06:57:39 +08:00
|
|
|
int &i1 = ctf(1.0f, 2.0);
|
2010-01-12 03:36:35 +08:00
|
|
|
float &f1 = ctf((short int)1, 1.0f);
|
2010-03-10 19:27:22 +08:00
|
|
|
ctf((long int)17, 2.0); // expected-error{{call to object of type 'ConvertToFunc' is ambiguous}}
|
2008-11-20 06:59:19 +08:00
|
|
|
ctf();
|
2010-01-12 03:36:35 +08:00
|
|
|
|
|
|
|
int &i2 = ctfd(1.0f, 2.0);
|
|
|
|
float &f2 = ctfd((short int)1, 1.0f);
|
2010-03-10 19:27:22 +08:00
|
|
|
ctfd((long int)17, 2.0); // expected-error{{call to object of type 'ConvertToFuncDerived' is ambiguous}}
|
2010-01-12 03:36:35 +08:00
|
|
|
ctfd();
|
2008-11-20 06:57:39 +08:00
|
|
|
}
|
2008-11-21 00:27:02 +08:00
|
|
|
|
|
|
|
struct HasMember {
|
|
|
|
int m;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Arrow1 {
|
|
|
|
HasMember* operator->();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Arrow2 {
|
|
|
|
Arrow1 operator->(); // expected-note{{candidate function}}
|
|
|
|
};
|
|
|
|
|
|
|
|
void test_arrow(Arrow1 a1, Arrow2 a2, const Arrow2 a3) {
|
|
|
|
int &i1 = a1->m;
|
|
|
|
int &i2 = a2->m;
|
2011-12-15 08:38:15 +08:00
|
|
|
a3->m; // expected-error{{no viable overloaded 'operator->'}}
|
2008-11-21 00:27:02 +08:00
|
|
|
}
|
2009-01-13 08:11:19 +08:00
|
|
|
|
|
|
|
struct CopyConBase {
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CopyCon : public CopyConBase {
|
|
|
|
CopyCon(const CopyConBase &Base);
|
|
|
|
|
|
|
|
CopyCon(const CopyConBase *Base) {
|
|
|
|
*this = *Base;
|
|
|
|
}
|
|
|
|
};
|
2009-02-04 08:32:51 +08:00
|
|
|
|
|
|
|
namespace N {
|
|
|
|
struct X { };
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace M {
|
|
|
|
N::X operator+(N::X, N::X);
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace M {
|
|
|
|
void test_X(N::X x) {
|
2009-02-05 00:44:47 +08:00
|
|
|
(void)(x + x);
|
2009-02-04 08:32:51 +08:00
|
|
|
}
|
|
|
|
}
|
2009-08-28 07:35:55 +08:00
|
|
|
|
|
|
|
struct AA { bool operator!=(AA&); };
|
|
|
|
struct BB : AA {};
|
|
|
|
bool x(BB y, BB z) { return y != z; }
|
2009-09-30 08:19:41 +08:00
|
|
|
|
|
|
|
|
|
|
|
struct AX {
|
2010-04-23 10:20:12 +08:00
|
|
|
AX& operator ->(); // expected-note {{declared here}}
|
2009-09-30 08:19:41 +08:00
|
|
|
int b;
|
|
|
|
};
|
|
|
|
|
|
|
|
void m() {
|
|
|
|
AX a;
|
|
|
|
a->b = 0; // expected-error {{circular pointer delegation detected}}
|
|
|
|
}
|
2009-09-30 09:01:30 +08:00
|
|
|
|
|
|
|
struct CircA {
|
2010-04-23 10:20:12 +08:00
|
|
|
struct CircB& operator->(); // expected-note {{declared here}}
|
2009-09-30 09:01:30 +08:00
|
|
|
int val;
|
|
|
|
};
|
|
|
|
struct CircB {
|
2010-04-23 10:20:12 +08:00
|
|
|
struct CircC& operator->(); // expected-note {{declared here}}
|
2009-09-30 09:01:30 +08:00
|
|
|
};
|
|
|
|
struct CircC {
|
2010-04-23 10:20:12 +08:00
|
|
|
struct CircA& operator->(); // expected-note {{declared here}}
|
2009-09-30 09:01:30 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void circ() {
|
|
|
|
CircA a;
|
|
|
|
a->val = 0; // expected-error {{circular pointer delegation detected}}
|
|
|
|
}
|
2009-11-06 00:36:20 +08:00
|
|
|
|
|
|
|
// PR5360: Arrays should lead to built-in candidates for subscript.
|
|
|
|
typedef enum {
|
2010-07-08 22:54:42 +08:00
|
|
|
LastReg = 23,
|
2009-11-06 00:36:20 +08:00
|
|
|
} Register;
|
|
|
|
class RegAlloc {
|
|
|
|
int getPriority(Register r) {
|
|
|
|
return usepri[r];
|
|
|
|
}
|
|
|
|
int usepri[LastReg + 1];
|
|
|
|
};
|
2009-11-19 04:39:26 +08:00
|
|
|
|
|
|
|
// PR5546: Don't generate incorrect and ambiguous overloads for multi-level
|
|
|
|
// arrays.
|
|
|
|
namespace pr5546
|
|
|
|
{
|
|
|
|
enum { X };
|
|
|
|
extern const char *const sMoveCommands[][2][2];
|
|
|
|
const char* a() { return sMoveCommands[X][0][0]; }
|
|
|
|
const char* b() { return (*(sMoveCommands+X))[0][0]; }
|
|
|
|
}
|
2009-11-19 07:10:33 +08:00
|
|
|
|
|
|
|
// PR5512 and its discussion
|
|
|
|
namespace pr5512 {
|
|
|
|
struct Y {
|
|
|
|
operator short();
|
|
|
|
operator float();
|
|
|
|
};
|
|
|
|
void g_test(Y y) {
|
|
|
|
short s = 0;
|
|
|
|
// DR507, this should be ambiguous, but we special-case assignment
|
|
|
|
s = y;
|
|
|
|
// Note: DR507, this is ambiguous as specified
|
|
|
|
//s += y;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct S {};
|
|
|
|
void operator +=(int&, S);
|
|
|
|
void f(S s) {
|
|
|
|
int i = 0;
|
|
|
|
i += s;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct A {operator int();};
|
|
|
|
int a;
|
|
|
|
void b(A x) {
|
|
|
|
a += x;
|
|
|
|
}
|
|
|
|
}
|
2010-01-07 10:04:15 +08:00
|
|
|
|
|
|
|
// PR5900
|
|
|
|
namespace pr5900 {
|
|
|
|
struct NotAnArray {};
|
|
|
|
void test0() {
|
|
|
|
NotAnArray x;
|
|
|
|
x[0] = 0; // expected-error {{does not provide a subscript operator}}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct NonConstArray {
|
|
|
|
int operator[](unsigned); // expected-note {{candidate}}
|
|
|
|
};
|
|
|
|
int test1() {
|
Rework base and member initialization in constructors, with several
(necessarily simultaneous) changes:
- CXXBaseOrMemberInitializer now contains only a single initializer
rather than a set of initialiation arguments + a constructor. The
single initializer covers all aspects of initialization, including
constructor calls as necessary but also cleanup of temporaries
created by the initializer (which we never handled
before!).
- Rework + simplify code generation for CXXBaseOrMemberInitializers,
since we can now just emit the initializer as an initializer.
- Switched base and member initialization over to the new
initialization code (InitializationSequence), so that it
- Improved diagnostics for the new initialization code when
initializing bases and members, to match the diagnostics produced
by the previous (special-purpose) code.
- Simplify the representation of type-checked constructor initializers in
templates; instead of keeping the fully-type-checked AST, which is
rather hard to undo at template instantiation time, throw away the
type-checked AST and store the raw expressions in the AST. This
simplifies instantiation, but loses a little but of information in
the AST.
- When type-checking implicit base or member initializers within a
dependent context, don't add the generated initializers into the
AST, because they'll look like they were explicit.
- Record in CXXConstructExpr when the constructor call is to
initialize a base class, so that CodeGen does not have to infer it
from context. This ensures that we call the right kind of
constructor.
There are also a few "opportunity" fixes here that were needed to not
regress, for example:
- Diagnose default-initialization of a const-qualified class that
does not have a user-declared default constructor. We had this
diagnostic specifically for bases and members, but missed it for
variables. That's fixed now.
- When defining the implicit constructors, destructor, and
copy-assignment operator, set the CurContext to that constructor
when we're defining the body.
llvm-svn: 94952
2010-01-31 17:12:51 +08:00
|
|
|
const NonConstArray x = NonConstArray();
|
2010-01-07 10:04:15 +08:00
|
|
|
return x[0]; // expected-error {{no viable overloaded operator[] for type}}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not really part of this PR, but implemented at the same time.
|
|
|
|
struct NotAFunction {};
|
|
|
|
void test2() {
|
|
|
|
NotAFunction x;
|
|
|
|
x(); // expected-error {{does not provide a call operator}}
|
|
|
|
}
|
|
|
|
}
|
2010-04-26 04:25:43 +08:00
|
|
|
|
|
|
|
// Operator lookup through using declarations.
|
|
|
|
namespace N {
|
|
|
|
struct X2 { };
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace N2 {
|
|
|
|
namespace M {
|
|
|
|
namespace Inner {
|
|
|
|
template<typename T>
|
|
|
|
N::X2 &operator<<(N::X2&, const T&);
|
|
|
|
}
|
|
|
|
using Inner::operator<<;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_lookup_through_using() {
|
|
|
|
using namespace N2::M;
|
|
|
|
N::X2 x;
|
|
|
|
x << 17;
|
|
|
|
}
|
2011-03-17 02:21:05 +08:00
|
|
|
|
|
|
|
namespace rdar9136502 {
|
|
|
|
struct X {
|
2013-06-04 08:28:46 +08:00
|
|
|
int i(); // expected-note{{possible target for call}}
|
|
|
|
int i(int); // expected-note{{possible target for call}}
|
2011-03-17 02:21:05 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Y {
|
2011-10-18 02:40:02 +08:00
|
|
|
Y &operator<<(int);
|
2011-03-17 02:21:05 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void f(X x, Y y) {
|
2013-06-04 03:46:44 +08:00
|
|
|
y << x
|
2013-06-04 08:28:46 +08:00
|
|
|
.i; // expected-error{{reference to non-static member function must be called; did you mean to call it with no arguments?}}
|
2011-03-17 02:21:05 +08:00
|
|
|
}
|
|
|
|
}
|
2011-05-05 08:13:13 +08:00
|
|
|
|
|
|
|
namespace rdar9222009 {
|
|
|
|
class StringRef {
|
|
|
|
inline bool operator==(StringRef LHS, StringRef RHS) { // expected-error{{overloaded 'operator==' must be a binary operator (has 3 parameters)}}
|
|
|
|
return !(LHS == RHS); // expected-error{{invalid operands to binary expression ('rdar9222009::StringRef' and 'rdar9222009::StringRef')}}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2012-01-18 05:27:43 +08:00
|
|
|
|
|
|
|
namespace PR11784 {
|
|
|
|
struct A { A& operator=(void (*x)()); };
|
|
|
|
void f();
|
|
|
|
void f(int);
|
|
|
|
void g() { A x; x = f; }
|
|
|
|
}
|
2013-03-04 09:30:55 +08:00
|
|
|
|
|
|
|
namespace test10 {
|
|
|
|
struct A {
|
|
|
|
void operator[](float (*fn)(int)); // expected-note 2 {{not viable: no overload of 'bar' matching 'float (*)(int)'}}
|
|
|
|
};
|
|
|
|
|
|
|
|
float foo(int);
|
|
|
|
float foo(float);
|
|
|
|
|
|
|
|
template <class T> T bar(T);
|
|
|
|
template <class T, class U> T bar(U);
|
|
|
|
|
|
|
|
void test(A &a) {
|
|
|
|
a[&foo];
|
|
|
|
a[foo];
|
|
|
|
|
|
|
|
a[&bar<int>]; // expected-error {{no viable overloaded operator[]}}
|
|
|
|
a[bar<int>]; // expected-error {{no viable overloaded operator[]}}
|
|
|
|
|
|
|
|
// If these fail, it's because we're not letting the overload
|
|
|
|
// resolution for operator| resolve the overload of 'bar'.
|
|
|
|
a[&bar<float>];
|
|
|
|
a[bar<float>];
|
|
|
|
}
|
|
|
|
}
|
2013-07-12 07:55:07 +08:00
|
|
|
|
|
|
|
struct InvalidOperatorEquals {
|
|
|
|
InvalidOperatorEquals operator=() = delete; // expected-error {{overloaded 'operator=' must be a binary operator}}
|
|
|
|
};
|
2013-08-29 04:35:35 +08:00
|
|
|
|
|
|
|
namespace PR7681 {
|
|
|
|
template <typename PT1, typename PT2> class PointerUnion;
|
|
|
|
void foo(PointerUnion<int*, float*> &Result) {
|
|
|
|
Result = 1; // expected-error {{no viable overloaded '='}} // expected-note {{type 'PointerUnion<int *, float *>' is incomplete}}
|
|
|
|
}
|
|
|
|
}
|
2014-01-31 06:24:05 +08:00
|
|
|
|
|
|
|
namespace PR14995 {
|
|
|
|
struct B {};
|
|
|
|
template<typename ...T> void operator++(B, T...) {}
|
|
|
|
|
|
|
|
void f() {
|
|
|
|
B b;
|
|
|
|
b++; // ok
|
|
|
|
++b; // ok
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename... T>
|
|
|
|
struct C {
|
|
|
|
void operator-- (T...) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
void g() {
|
|
|
|
C<int> postfix;
|
|
|
|
C<> prefix;
|
|
|
|
postfix--; // ok
|
|
|
|
--prefix; // ok
|
|
|
|
}
|
|
|
|
|
|
|
|
struct D {};
|
|
|
|
template<typename T> void operator++(D, T) {}
|
|
|
|
|
|
|
|
void h() {
|
|
|
|
D d;
|
|
|
|
d++; // ok
|
|
|
|
++d; // expected-error{{cannot increment value of type 'PR14995::D'}}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename...T> struct E {
|
|
|
|
void operator++(T...) {} // expected-error{{parameter of overloaded post-increment operator must have type 'int' (not 'char')}}
|
|
|
|
};
|
|
|
|
|
|
|
|
E<char> e; // expected-note {{in instantiation of template class 'PR14995::E<char>' requested here}}
|
|
|
|
|
|
|
|
struct F {
|
|
|
|
template<typename... T>
|
|
|
|
int operator++ (T...) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
int k1 = F().operator++(0, 0);
|
|
|
|
int k2 = F().operator++('0');
|
|
|
|
// expected-error@-5 {{overloaded 'operator++' must be a unary or binary operator}}
|
|
|
|
// expected-note@-3 {{in instantiation of function template specialization 'PR14995::F::operator++<int, int>' requested here}}
|
|
|
|
// expected-error@-4 {{no matching member function for call to 'operator++'}}
|
|
|
|
// expected-note@-8 {{candidate template ignored: substitution failure}}
|
|
|
|
// expected-error@-9 {{parameter of overloaded post-increment operator must have type 'int' (not 'char')}}
|
|
|
|
// expected-note@-6 {{in instantiation of function template specialization 'PR14995::F::operator++<char>' requested here}}
|
|
|
|
// expected-error@-7 {{no matching member function for call to 'operator++'}}
|
|
|
|
// expected-note@-12 {{candidate template ignored: substitution failure}}
|
|
|
|
} // namespace PR14995
|
|
|
|
|
2014-05-17 09:58:45 +08:00
|
|
|
namespace ConversionVersusTemplateOrdering {
|
|
|
|
struct A {
|
|
|
|
operator short() = delete;
|
|
|
|
template <typename T> operator T();
|
|
|
|
} a;
|
|
|
|
struct B {
|
|
|
|
template <typename T> operator T();
|
|
|
|
operator short() = delete;
|
|
|
|
} b;
|
|
|
|
int x = a;
|
|
|
|
int y = b;
|
|
|
|
}
|
2014-09-24 04:31:39 +08:00
|
|
|
|
|
|
|
namespace NoADLForMemberOnlyOperators {
|
|
|
|
template<typename T> struct A { typename T::error e; }; // expected-error {{type 'char' cannot be used prior to '::'}}
|
|
|
|
template<typename T> struct B { int n; };
|
|
|
|
|
|
|
|
void f(B<A<void> > b1, B<A<int> > b2, B<A<char> > b3) {
|
|
|
|
b1 = b1; // ok, does not instantiate A<void>.
|
|
|
|
(void)b1->n; // expected-error {{is not a pointer}}
|
|
|
|
b2[3]; // expected-error {{does not provide a subscript}}
|
|
|
|
b3 / 0; // expected-note {{in instantiation of}} expected-error {{invalid operands to}}
|
|
|
|
}
|
|
|
|
}
|
2017-07-31 08:24:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
namespace PR27027 {
|
|
|
|
template <class T> void operator+(T, T) = delete; // expected-note 4 {{candidate}}
|
|
|
|
template <class T> void operator+(T) = delete; // expected-note 4 {{candidate}}
|
|
|
|
|
|
|
|
struct A {} a_global;
|
|
|
|
void f() {
|
|
|
|
A a;
|
|
|
|
+a; // expected-error {{overload resolution selected deleted operator '+'}}
|
|
|
|
a + a; // expected-error {{overload resolution selected deleted operator '+'}}
|
|
|
|
bool operator+(A);
|
|
|
|
extern bool operator+(A, A);
|
|
|
|
+a; // OK
|
|
|
|
a + a;
|
|
|
|
}
|
|
|
|
bool test_global_1 = +a_global; // expected-error {{overload resolution selected deleted operator '+'}}
|
|
|
|
bool test_global_2 = a_global + a_global; // expected-error {{overload resolution selected deleted operator '+'}}
|
|
|
|
}
|