re PR c++/92973 (Silently accepting defaulted comparison operators in C++11 .. 17)
authorJakub Jelinek <jakub@redhat.com>
Fri, 20 Dec 2019 23:18:09 +0000 (00:18 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 20 Dec 2019 23:18:09 +0000 (00:18 +0100)
PR c++/92973
* method.c (early_check_defaulted_comparison): For C++17 and earlier
diagnose defaulted comparison operators.

* g++.dg/cpp0x/spaceship-eq1.C: New test.

From-SVN: r279682

gcc/cp/ChangeLog
gcc/cp/method.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/spaceship-eq1.C [new file with mode: 0644]

index 5a9a648d3336fb1416f15f007dd7489035d00a1a..07200ad21e5b5c2539b33f40e4ed73cf3b37d389 100644 (file)
@@ -1,5 +1,9 @@
 2019-12-20  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/92973
+       * method.c (early_check_defaulted_comparison): For C++17 and earlier
+       diagnose defaulted comparison operators.
+
        PR c++/92666
        * call.c (convert_arg_to_ellipsis): For floating point or
        decltype(nullptr) arguments call mark_rvalue_use.
index 97c27c51ea3d38c872aabebea546eeca88e457e3..248a0e55f06e3cf4a66081c3195b8e5609a901d6 100644 (file)
@@ -1092,6 +1092,13 @@ early_check_defaulted_comparison (tree fn)
     ctx = DECL_FRIEND_CONTEXT (fn);
   bool ok = true;
 
+  if (cxx_dialect < cxx2a)
+    {
+      error_at (loc, "defaulted %qD only available with %<-std=c++2a%> or "
+                    "%<-std=gnu++2a%>", fn);
+      return false;
+    }
+
   if (!DECL_OVERLOADED_OPERATOR_IS (fn, SPACESHIP_EXPR)
       && !same_type_p (TREE_TYPE (TREE_TYPE (fn)), boolean_type_node))
     {
index dd9e529ebcaccf7ad9f6898ff5abd74c5e40a58f..40568bb98be8c036a6e07dfff5ec11e029f80fd0 100644 (file)
@@ -1,5 +1,8 @@
 2019-12-20  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/92973
+       * g++.dg/cpp0x/spaceship-eq1.C: New test.
+
        PR c++/92666
        * g++.dg/warn/Wunused-var-36.C: New test.
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/spaceship-eq1.C b/gcc/testsuite/g++.dg/cpp0x/spaceship-eq1.C
new file mode 100644 (file)
index 0000000..2e0ad0c
--- /dev/null
@@ -0,0 +1,5 @@
+// PR c++/92973
+// { dg-do compile { target c++11 } }
+
+struct S { bool operator==(const S&) const = default; int s; };        // { dg-error "only available with" "" { target c++17_down } }
+struct T { bool operator!=(const T&) const = default; int t; };        // { dg-error "only available with" "" { target c++17_down } }