public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C++ PATCH] Disallow defaulted comparison operators in C++11-17 modes (PR c++/92973)
@ 2019-12-17 21:45 Jakub Jelinek
  2019-12-20 23:15 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2019-12-17 21:45 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

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?

2019-12-17  Jakub Jelinek  <jakub@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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [C++ PATCH] Disallow defaulted comparison operators in C++11-17 modes (PR c++/92973)
  2019-12-17 21:45 [C++ PATCH] Disallow defaulted comparison operators in C++11-17 modes (PR c++/92973) Jakub Jelinek
@ 2019-12-20 23:15 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2019-12-20 23:15 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

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  <jakub@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
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-12-20 23:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-17 21:45 [C++ PATCH] Disallow defaulted comparison operators in C++11-17 modes (PR c++/92973) Jakub Jelinek
2019-12-20 23:15 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).