summaryrefslogtreecommitdiff
path: root/test/SemaCXX/default-assignment-operator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/SemaCXX/default-assignment-operator.cpp')
-rw-r--r--test/SemaCXX/default-assignment-operator.cpp87
1 files changed, 70 insertions, 17 deletions
diff --git a/test/SemaCXX/default-assignment-operator.cpp b/test/SemaCXX/default-assignment-operator.cpp
index e57a898f2f10..80ceb3768d9e 100644
--- a/test/SemaCXX/default-assignment-operator.cpp
+++ b/test/SemaCXX/default-assignment-operator.cpp
@@ -1,16 +1,34 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
-
-class Base { // expected-error {{cannot define the implicit copy assignment operator for 'Base', because non-static reference member 'ref' cannot use copy assignment operator}} \
- // expected-warning{{class 'Base' does not declare any constructor to initialize its non-modifiable members}}
- int &ref; // expected-note {{declared here}} \
- // expected-note{{reference member 'ref' will never be initialized}}
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+class Base { // expected-warning{{class 'Base' does not declare any constructor to initialize its non-modifiable members}}
+#if __cplusplus <= 199711L
+// expected-error@-2 {{cannot define the implicit copy assignment operator for 'Base', because non-static reference member 'ref' cannot use copy assignment operator}}
+#endif
+
+ int &ref; // expected-note{{reference member 'ref' will never be initialized}}
+#if __cplusplus <= 199711L
+ // expected-note@-2 {{declared here}}
+#else
+ // expected-note@-4 2 {{copy assignment operator of 'Base' is implicitly deleted because field 'ref' is of reference type 'int &'}}
+#endif
};
-class X : Base { // // expected-error {{cannot define the implicit copy assignment operator for 'X', because non-static const member 'cint' cannot use copy assignment operator}} \
-// expected-note{{assignment operator for 'Base' first required here}}
+class X : Base {
+#if __cplusplus <= 199711L
+// expected-note@-2 {{assignment operator for 'Base' first required here}}
+// expected-error@-3 {{cannot define the implicit copy assignment operator for 'X', because non-static const member 'cint' cannot use copy assignment operator}}
+#else
+// expected-note@-5 2 {{copy assignment operator of 'X' is implicitly deleted because base class 'Base' has a deleted copy assignment operator}}
+#endif
+
public:
X();
- const int cint; // expected-note {{declared here}}
+ const int cint;
+#if __cplusplus <= 199711L
+// expected-note@-2 {{declared here}}
+#endif
};
struct Y : X {
@@ -28,8 +46,17 @@ Z z2;
// Test1
void f(X x, const X cx) {
- x = cx; // expected-note{{assignment operator for 'X' first required here}}
x = cx;
+#if __cplusplus <= 199711L
+ // expected-note@-2 {{assignment operator for 'X' first required here}}
+#else
+ // expected-error@-4 {{object of type 'X' cannot be assigned because its copy assignment operator is implicitly deleted}}
+#endif
+
+ x = cx;
+#if __cplusplus >= 201103L
+ // expected-error@-2 {{object of type 'X' cannot be assigned because its copy assignment operator is implicitly deleted}}
+#endif
z1 = z2;
}
@@ -73,36 +100,62 @@ void i() {
// Test5
-class E1 { // expected-error{{cannot define the implicit copy assignment operator for 'E1', because non-static const member 'a' cannot use copy assignment operator}}
+class E1 {
+#if __cplusplus <= 199711L
+// expected-error@-2 {{cannot define the implicit copy assignment operator for 'E1', because non-static const member 'a' cannot use copy assignment operator}}
+#endif
public:
- const int a; // expected-note{{declared here}}
- E1() : a(0) {}
+ const int a;
+#if __cplusplus <= 199711L
+// expected-note@-2 {{declared here}}
+#else
+// expected-note@-4 {{copy assignment operator of 'E1' is implicitly deleted because field 'a' is of const-qualified type 'const int'}}
+#endif
+ E1() : a(0) {}
};
E1 e1, e2;
void j() {
- e1 = e2; // expected-note{{assignment operator for 'E1' first required here}}
+ e1 = e2;
+#if __cplusplus <= 199711L
+ // expected-note@-2 {{assignment operator for 'E1' first required here}}
+#else
+ // expected-error@-4 {{object of type 'E1' cannot be assigned because its copy assignment operator is implicitly deleted}}
+#endif
}
namespace ProtectedCheck {
struct X {
protected:
- X &operator=(const X&); // expected-note{{declared protected here}}
+ X &operator=(const X&);
+#if __cplusplus <= 199711L
+ // expected-note@-2 {{declared protected here}}
+#endif
};
struct Y : public X { };
void f(Y y) { y = y; }
- struct Z { // expected-error{{'operator=' is a protected member of 'ProtectedCheck::X'}}
+ struct Z {
+#if __cplusplus <= 199711L
+ // expected-error@-2 {{'operator=' is a protected member of 'ProtectedCheck::X'}}
+#endif
X x;
+#if __cplusplus >= 201103L
+ // expected-note@-2 {{copy assignment operator of 'Z' is implicitly deleted because field 'x' has an inaccessible copy assignment operator}}
+#endif
};
- void f(Z z) { z = z; } // expected-note{{implicit copy assignment operator}}
-
+ void f(Z z) { z = z; }
+#if __cplusplus <= 199711L
+ // expected-note@-2 {{implicit copy assignment operator}}
+#else
+ // expected-error@-4 {{object of type 'ProtectedCheck::Z' cannot be assigned because its copy assignment operator is implicitly deleted}}
+#endif
}
namespace MultiplePaths {