[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaCXX / copy-assignment.cpp
blobda548b7dea11b6a21cb9c6e755fdd1a1910459fe
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++98
3 // RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++11
5 #if __cplusplus >= 201103L
6 // expected-note@+3 2 {{candidate constructor}}
7 // expected-note@+2 {{passing argument to parameter here}}
8 #endif
9 struct A {
12 struct ConvertibleToA {
13 operator A();
16 struct ConvertibleToConstA {
17 #if __cplusplus >= 201103L
18 // expected-note@+2 {{candidate function}}
19 #endif
20 operator const A();
23 struct B {
24 B& operator=(B&); // expected-note 4 {{candidate function}}
27 struct ConvertibleToB {
28 operator B();
31 struct ConvertibleToBref {
32 operator B&();
35 struct ConvertibleToConstB {
36 operator const B();
39 struct ConvertibleToConstBref {
40 operator const B&();
43 struct C {
44 int operator=(int); // expected-note{{candidate function}}
45 long operator=(long); // expected-note{{candidate function}}
46 int operator+=(int); // expected-note{{candidate function}}
47 int operator+=(long); // expected-note{{candidate function}}
50 struct D {
51 D& operator+=(const D &);
54 struct ConvertibleToInt {
55 operator int();
58 void test() {
59 A a, na;
60 const A constA = A();
61 ConvertibleToA convertibleToA;
62 ConvertibleToConstA convertibleToConstA;
64 B b, nb;
65 const B constB = B();
66 ConvertibleToB convertibleToB;
67 ConvertibleToBref convertibleToBref;
68 ConvertibleToConstB convertibleToConstB;
69 ConvertibleToConstBref convertibleToConstBref;
71 C c, nc;
72 const C constC = C();
74 D d, nd;
75 const D constD = D();
77 ConvertibleToInt convertibleToInt;
79 na = a;
80 na = constA;
81 na = convertibleToA;
82 #if __cplusplus >= 201103L
83 // expected-error@+2 {{no viable conversion}}
84 #endif
85 na = convertibleToConstA;
86 na += a; // expected-error{{no viable overloaded '+='}}
88 nb = b;
89 nb = constB; // expected-error{{no viable overloaded '='}}
90 nb = convertibleToB; // expected-error{{no viable overloaded '='}}
91 nb = convertibleToBref;
92 nb = convertibleToConstB; // expected-error{{no viable overloaded '='}}
93 nb = convertibleToConstBref; // expected-error{{no viable overloaded '='}}
95 nc = c;
96 nc = constC;
97 nc = 1;
98 nc = 1L;
99 nc = 1.0; // expected-error{{use of overloaded operator '=' is ambiguous}}
100 nc += 1;
101 nc += 1L;
102 nc += 1.0; // expected-error{{use of overloaded operator '+=' is ambiguous}}
104 nd = d;
105 nd += d;
106 nd += constD;
108 int i;
109 i = convertibleToInt;
110 i = a; // expected-error{{assigning to 'int' from incompatible type 'A'}}
113 // Don't crash
114 namespace test1 {
115 template<typename T> class A : public unknown::X { // expected-error {{undeclared identifier 'unknown'}} expected-error {{expected class name}}
116 A(UndeclaredType n) : X(n) {} // expected-error {{unknown type name 'UndeclaredType'}}
117 // expected-error@-1 {{member initializer 'X' does not name a non-static data member or base class}}
119 template<typename T> class B : public A<T> {
120 virtual void foo() {}
122 extern template class A<char>;
123 extern template class B<char>;