On 12/17/19 3:59 PM, Jakub Jelinek wrote:
Hi!

As discussed on IRC, defaulted comparison operators were added only in
C++2a, so we shouldn't accept it in older standard modes.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

2019-12-17  Jakub Jelinek  <ja...@redhat.com>

        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.

--- gcc/cp/method.c.jj  2019-12-17 15:28:57.819285145 +0100
+++ gcc/cp/method.c     2019-12-17 16:21:24.462870308 +0100
@@ -1092,6 +1092,13 @@ early_check_defaulted_comparison (tree f
      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))
      {
--- gcc/testsuite/g++.dg/cpp0x/spaceship-eq1.C.jj       2019-12-17 
16:24:55.303697061 +0100
+++ gcc/testsuite/g++.dg/cpp0x/spaceship-eq1.C  2019-12-17 16:24:29.070091886 
+0100
@@ -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 } }

        Jakub


Reply via email to