xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/copy-assignment.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuc struct A {
3*f4a2713aSLionel Sambuc };
4*f4a2713aSLionel Sambuc 
5*f4a2713aSLionel Sambuc struct ConvertibleToA {
6*f4a2713aSLionel Sambuc   operator A();
7*f4a2713aSLionel Sambuc };
8*f4a2713aSLionel Sambuc 
9*f4a2713aSLionel Sambuc struct ConvertibleToConstA {
10*f4a2713aSLionel Sambuc   operator const A();
11*f4a2713aSLionel Sambuc };
12*f4a2713aSLionel Sambuc 
13*f4a2713aSLionel Sambuc struct B {
14*f4a2713aSLionel Sambuc   B& operator=(B&);  // expected-note 4 {{candidate function}}
15*f4a2713aSLionel Sambuc };
16*f4a2713aSLionel Sambuc 
17*f4a2713aSLionel Sambuc struct ConvertibleToB {
18*f4a2713aSLionel Sambuc   operator B();
19*f4a2713aSLionel Sambuc };
20*f4a2713aSLionel Sambuc 
21*f4a2713aSLionel Sambuc struct ConvertibleToBref {
22*f4a2713aSLionel Sambuc   operator B&();
23*f4a2713aSLionel Sambuc };
24*f4a2713aSLionel Sambuc 
25*f4a2713aSLionel Sambuc struct ConvertibleToConstB {
26*f4a2713aSLionel Sambuc   operator const B();
27*f4a2713aSLionel Sambuc };
28*f4a2713aSLionel Sambuc 
29*f4a2713aSLionel Sambuc struct ConvertibleToConstBref {
30*f4a2713aSLionel Sambuc   operator const B&();
31*f4a2713aSLionel Sambuc };
32*f4a2713aSLionel Sambuc 
33*f4a2713aSLionel Sambuc struct C {
34*f4a2713aSLionel Sambuc   int operator=(int); // expected-note{{candidate function}}
35*f4a2713aSLionel Sambuc   long operator=(long); // expected-note{{candidate function}}
36*f4a2713aSLionel Sambuc   int operator+=(int); // expected-note{{candidate function}}
37*f4a2713aSLionel Sambuc   int operator+=(long); // expected-note{{candidate function}}
38*f4a2713aSLionel Sambuc };
39*f4a2713aSLionel Sambuc 
40*f4a2713aSLionel Sambuc struct D {
41*f4a2713aSLionel Sambuc   D& operator+=(const D &);
42*f4a2713aSLionel Sambuc };
43*f4a2713aSLionel Sambuc 
44*f4a2713aSLionel Sambuc struct ConvertibleToInt {
45*f4a2713aSLionel Sambuc   operator int();
46*f4a2713aSLionel Sambuc };
47*f4a2713aSLionel Sambuc 
test()48*f4a2713aSLionel Sambuc void test() {
49*f4a2713aSLionel Sambuc   A a, na;
50*f4a2713aSLionel Sambuc   const A constA = A();
51*f4a2713aSLionel Sambuc   ConvertibleToA convertibleToA;
52*f4a2713aSLionel Sambuc   ConvertibleToConstA convertibleToConstA;
53*f4a2713aSLionel Sambuc 
54*f4a2713aSLionel Sambuc   B b, nb;
55*f4a2713aSLionel Sambuc   const B constB = B();
56*f4a2713aSLionel Sambuc   ConvertibleToB convertibleToB;
57*f4a2713aSLionel Sambuc   ConvertibleToBref convertibleToBref;
58*f4a2713aSLionel Sambuc   ConvertibleToConstB convertibleToConstB;
59*f4a2713aSLionel Sambuc   ConvertibleToConstBref convertibleToConstBref;
60*f4a2713aSLionel Sambuc 
61*f4a2713aSLionel Sambuc   C c, nc;
62*f4a2713aSLionel Sambuc   const C constC = C();
63*f4a2713aSLionel Sambuc 
64*f4a2713aSLionel Sambuc   D d, nd;
65*f4a2713aSLionel Sambuc   const D constD = D();
66*f4a2713aSLionel Sambuc 
67*f4a2713aSLionel Sambuc   ConvertibleToInt convertibleToInt;
68*f4a2713aSLionel Sambuc 
69*f4a2713aSLionel Sambuc   na = a;
70*f4a2713aSLionel Sambuc   na = constA;
71*f4a2713aSLionel Sambuc   na = convertibleToA;
72*f4a2713aSLionel Sambuc   na = convertibleToConstA;
73*f4a2713aSLionel Sambuc   na += a; // expected-error{{no viable overloaded '+='}}
74*f4a2713aSLionel Sambuc 
75*f4a2713aSLionel Sambuc   nb = b;
76*f4a2713aSLionel Sambuc   nb = constB;  // expected-error{{no viable overloaded '='}}
77*f4a2713aSLionel Sambuc   nb = convertibleToB; // expected-error{{no viable overloaded '='}}
78*f4a2713aSLionel Sambuc   nb = convertibleToBref;
79*f4a2713aSLionel Sambuc   nb = convertibleToConstB; // expected-error{{no viable overloaded '='}}
80*f4a2713aSLionel Sambuc   nb = convertibleToConstBref; // expected-error{{no viable overloaded '='}}
81*f4a2713aSLionel Sambuc 
82*f4a2713aSLionel Sambuc   nc = c;
83*f4a2713aSLionel Sambuc   nc = constC;
84*f4a2713aSLionel Sambuc   nc = 1;
85*f4a2713aSLionel Sambuc   nc = 1L;
86*f4a2713aSLionel Sambuc   nc = 1.0; // expected-error{{use of overloaded operator '=' is ambiguous}}
87*f4a2713aSLionel Sambuc   nc += 1;
88*f4a2713aSLionel Sambuc   nc += 1L;
89*f4a2713aSLionel Sambuc   nc += 1.0; // expected-error{{use of overloaded operator '+=' is ambiguous}}
90*f4a2713aSLionel Sambuc 
91*f4a2713aSLionel Sambuc   nd = d;
92*f4a2713aSLionel Sambuc   nd += d;
93*f4a2713aSLionel Sambuc   nd += constD;
94*f4a2713aSLionel Sambuc 
95*f4a2713aSLionel Sambuc   int i;
96*f4a2713aSLionel Sambuc   i = convertibleToInt;
97*f4a2713aSLionel Sambuc   i = a; // expected-error{{assigning to 'int' from incompatible type 'A'}}
98*f4a2713aSLionel Sambuc }
99*f4a2713aSLionel Sambuc 
100*f4a2713aSLionel Sambuc // <rdar://problem/8315440>: Don't crash
101*f4a2713aSLionel Sambuc namespace test1 {
102*f4a2713aSLionel Sambuc   template<typename T> class A : public unknown::X { // expected-error {{undeclared identifier 'unknown'}} expected-error {{expected class name}}
A(UndeclaredType n)103*f4a2713aSLionel Sambuc     A(UndeclaredType n) : X(n) {} // expected-error {{unknown type name 'UndeclaredType'}}
104*f4a2713aSLionel Sambuc   };
105*f4a2713aSLionel Sambuc   template<typename T> class B : public A<T>     {
foo()106*f4a2713aSLionel Sambuc     virtual void foo() {}
107*f4a2713aSLionel Sambuc   };
108*f4a2713aSLionel Sambuc   extern template class A<char>;
109*f4a2713aSLionel Sambuc   extern template class B<char>;
110*f4a2713aSLionel Sambuc }
111