aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2018-06-12 20:20:11 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2018-06-12 20:20:11 +0000
commit4db9ca8624e902b668ef394cf81e68e4ed5faa89 (patch)
tree4ac1af0c3684d81cd27dc2dee67e25f84978fc90 /gcc
parent84a9d3b6c1f1de2aa6b5bef700f51b2e7c0bc600 (diff)
downloadgcc-4db9ca8624e902b668ef394cf81e68e4ed5faa89.zip
gcc-4db9ca8624e902b668ef394cf81e68e4ed5faa89.tar.gz
gcc-4db9ca8624e902b668ef394cf81e68e4ed5faa89.tar.bz2
Core issue 1331 - const mismatch with defaulted copy constructor
Core issue 1331 - const mismatch with defaulted copy constructor * class.c (check_bases_and_members): When checking a defaulted function, mark it as deleted rather than giving an error. * g++.dg/cpp0x/defaulted15.C (struct F): Remove dg-error. * g++.dg/cpp0x/defaulted52.C: New test. * g++.dg/cpp0x/defaulted53.C: New test. * g++.dg/cpp0x/defaulted54.C: New test. * g++.dg/cpp0x/defaulted55.C: New test. * g++.dg/cpp0x/defaulted56.C: New test. * g++.dg/cpp0x/defaulted57.C: New test. * g++.dg/cpp0x/defaulted58.C: New test. * g++.dg/cpp0x/defaulted59.C: New test. * g++.dg/cpp0x/defaulted60.C: New test. From-SVN: r261526
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/class.c6
-rw-r--r--gcc/testsuite/ChangeLog14
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/defaulted15.C3
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/defaulted52.C20
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/defaulted53.C35
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/defaulted54.C18
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/defaulted55.C19
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/defaulted56.C25
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/defaulted57.C25
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/defaulted58.C22
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/defaulted59.C12
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/defaulted60.C18
13 files changed, 218 insertions, 5 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 585f111..726fd7f 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2018-06-12 Marek Polacek <polacek@redhat.com>
+
+ Core issue 1331 - const mismatch with defaulted copy constructor
+ * class.c (check_bases_and_members): When checking a defaulted
+ function, mark it as deleted rather than giving an error.
+
2018-06-11 Jason Merrill <jason@redhat.com>
PR c++/85792 -Wctor-dtor-privacy and inherited constructor.
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index fbf3903..b6e78c6 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -5660,9 +5660,9 @@ check_bases_and_members (tree t)
if (fn_const_p && !imp_const_p)
/* If the function is defaulted outside the class, we just
- give the synthesis error. */
- error ("%q+D declared to take const reference, but implicit "
- "declaration would take non-const", fn);
+ give the synthesis error. Core Issue #1331 says this is
+ no longer ill-formed, it is defined as deleted instead. */
+ DECL_DELETED_FN (fn) = true;
}
defaulted_late_check (fn);
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 6acc358..e69ab64 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,17 @@
+2018-06-12 Marek Polacek <polacek@redhat.com>
+
+ Core issue 1331 - const mismatch with defaulted copy constructor
+ * g++.dg/cpp0x/defaulted15.C (struct F): Remove dg-error.
+ * g++.dg/cpp0x/defaulted52.C: New test.
+ * g++.dg/cpp0x/defaulted53.C: New test.
+ * g++.dg/cpp0x/defaulted54.C: New test.
+ * g++.dg/cpp0x/defaulted55.C: New test.
+ * g++.dg/cpp0x/defaulted56.C: New test.
+ * g++.dg/cpp0x/defaulted57.C: New test.
+ * g++.dg/cpp0x/defaulted58.C: New test.
+ * g++.dg/cpp0x/defaulted59.C: New test.
+ * g++.dg/cpp0x/defaulted60.C: New test.
+
2018-06-12 David Malcolm <dmalcolm@redhat.com>
PR other/69968
diff --git a/gcc/testsuite/g++.dg/cpp0x/defaulted15.C b/gcc/testsuite/g++.dg/cpp0x/defaulted15.C
index fabcc23..1e0b354 100644
--- a/gcc/testsuite/g++.dg/cpp0x/defaulted15.C
+++ b/gcc/testsuite/g++.dg/cpp0x/defaulted15.C
@@ -48,8 +48,7 @@ struct F
struct G: public F
{
- // Can't be const because F copy ctor isn't.
- G(const G&) = default; // { dg-error "const" }
+ G(const G&) = default;
};
struct H
diff --git a/gcc/testsuite/g++.dg/cpp0x/defaulted52.C b/gcc/testsuite/g++.dg/cpp0x/defaulted52.C
new file mode 100644
index 0000000..c617230
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/defaulted52.C
@@ -0,0 +1,20 @@
+// Core Issue #1331 (const mismatch with defaulted copy constructor)
+// { dg-do compile { target c++11 } }
+
+struct M
+{
+ M();
+ // So that W wouldn't have had "const W&" copy ctor if it were
+ // implicitly declared.
+ M(M&);
+};
+
+template<typename T> struct W
+{
+ W();
+ // This should now compile and be =deleted.
+ W(const W&) = default;
+ T t;
+};
+
+W<M> w;
diff --git a/gcc/testsuite/g++.dg/cpp0x/defaulted53.C b/gcc/testsuite/g++.dg/cpp0x/defaulted53.C
new file mode 100644
index 0000000..8147e7e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/defaulted53.C
@@ -0,0 +1,35 @@
+// Core Issue #1331 (const mismatch with defaulted copy constructor)
+// { dg-do compile { target c++11 } }
+
+struct M
+{
+ M& operator=(M&);
+};
+
+struct R
+{
+ R& operator=(R&) = default;
+ M m;
+};
+
+struct S
+{
+ S& operator=(const S&) = default;
+ M m;
+};
+
+struct T
+{
+ // If F is an assignment operator, and the return type of T1
+ // differs from the return type of T2 the program is ill-formed.
+ T operator=(T&) = default; // { dg-error "defaulted" }
+ M m;
+};
+
+struct U
+{
+ // If F is an assignment operator, and T1's parameter type is
+ // not a reference, the program is ill-formed.
+ U& operator=(U) = default; // { dg-error "defaulted" }
+ M m;
+};
diff --git a/gcc/testsuite/g++.dg/cpp0x/defaulted54.C b/gcc/testsuite/g++.dg/cpp0x/defaulted54.C
new file mode 100644
index 0000000..f8ddc4e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/defaulted54.C
@@ -0,0 +1,18 @@
+// Core Issue #1331 (const mismatch with defaulted copy constructor)
+// { dg-do compile { target c++11 } }
+
+struct M
+{
+ M();
+ M(M&);
+};
+
+template<typename T> struct W
+{
+ W();
+ W(const W&) = default; // { dg-error "binding" }
+ T t;
+};
+
+W<M> w;
+W<M> w2 = w; // { dg-error "use of deleted function" }
diff --git a/gcc/testsuite/g++.dg/cpp0x/defaulted55.C b/gcc/testsuite/g++.dg/cpp0x/defaulted55.C
new file mode 100644
index 0000000..04cfc17
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/defaulted55.C
@@ -0,0 +1,19 @@
+// Core Issue #1331 (const mismatch with defaulted copy constructor)
+// { dg-do compile { target c++11 } }
+
+struct M
+{
+ M();
+ M(M&);
+};
+
+template<typename T> struct W
+{
+ W();
+ W(W&) = default;
+ // T1 and T2 may have differing ref-qualifiers (copy assign op).
+ constexpr W& operator=(const W&) && = default; // { dg-error "defaulted" "" { target c++11_down } }
+ T t;
+};
+
+W<M> w;
diff --git a/gcc/testsuite/g++.dg/cpp0x/defaulted56.C b/gcc/testsuite/g++.dg/cpp0x/defaulted56.C
new file mode 100644
index 0000000..e7ce12c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/defaulted56.C
@@ -0,0 +1,25 @@
+// Core Issue #1331 (const mismatch with defaulted copy constructor)
+// { dg-do compile { target c++11 } }
+
+// If T2 (what would be the implicit declaration) has a parameter of
+// type const C&, the corresponding parameter of T1 may be of type C&.
+
+struct S
+{
+ constexpr S(S &) = default;
+};
+
+struct T
+{
+ constexpr T(volatile T &) = default; // { dg-error "defaulted" }
+};
+
+struct U
+{
+ constexpr U(const volatile U &) = default; // { dg-error "defaulted" }
+};
+
+struct V
+{
+ constexpr V(const V &) = default;
+};
diff --git a/gcc/testsuite/g++.dg/cpp0x/defaulted57.C b/gcc/testsuite/g++.dg/cpp0x/defaulted57.C
new file mode 100644
index 0000000..37fb7dd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/defaulted57.C
@@ -0,0 +1,25 @@
+// Core Issue #1331 (const mismatch with defaulted copy constructor)
+// { dg-do compile { target c++11 } }
+
+// If T2 (what would be the implicit declaration) has a parameter of
+// type const C&, the corresponding parameter of T1 may be of type C&.
+
+struct S
+{
+ S& operator=(S &) = default;
+};
+
+struct T
+{
+ T& operator=(volatile T &) = default; // { dg-error "defaulted" }
+};
+
+struct U
+{
+ U& operator=(const volatile U &) = default; // { dg-error "defaulted" }
+};
+
+struct V
+{
+ V& operator=(const V &) = default;
+};
diff --git a/gcc/testsuite/g++.dg/cpp0x/defaulted58.C b/gcc/testsuite/g++.dg/cpp0x/defaulted58.C
new file mode 100644
index 0000000..920a4ad
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/defaulted58.C
@@ -0,0 +1,22 @@
+// Core Issue #1331 (const mismatch with defaulted copy constructor)
+// { dg-do compile { target c++11 } }
+
+struct M
+{
+ M() = default;
+ M& operator=(M&);
+};
+
+template<typename T> struct W
+{
+ W() = default;
+ W& operator=(const W&) = default; // { dg-error "binding" }
+ T t;
+};
+
+int
+main ()
+{
+ W<M> w1, w2;
+ w1 = w2; // { dg-error "use of deleted function" }
+}
diff --git a/gcc/testsuite/g++.dg/cpp0x/defaulted59.C b/gcc/testsuite/g++.dg/cpp0x/defaulted59.C
new file mode 100644
index 0000000..4f871d7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/defaulted59.C
@@ -0,0 +1,12 @@
+// Core Issue #1331 (const mismatch with defaulted copy constructor)
+// { dg-do compile { target c++11 } }
+
+struct M
+{
+ M(M&) = default;
+};
+
+struct W : public M
+{
+ W(const W&) = default;
+};
diff --git a/gcc/testsuite/g++.dg/cpp0x/defaulted60.C b/gcc/testsuite/g++.dg/cpp0x/defaulted60.C
new file mode 100644
index 0000000..ad02523
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/defaulted60.C
@@ -0,0 +1,18 @@
+// Core Issue #1331 (const mismatch with defaulted copy constructor)
+// { dg-do compile { target c++11 } }
+
+struct M
+{
+ M(M&);
+};
+
+struct W
+{
+ W();
+ W(const W&);
+ M m;
+};
+
+// Not first declaration.
+W::W(const W&) = default; // { dg-error "binding" }
+W w;