Re: [C++ PATCH] Implement D1959R0, remove weak_equality and strong_equality.

2019-11-07 Thread Jakub Jelinek
On Thu, Nov 07, 2019 at 05:05:16PM +, Jason Merrill wrote:
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp2a/spaceship-scalar1-neg.C
> @@ -0,0 +1,25 @@
> +// { dg-do run { target c++2a } }
> +
> +#include 
> +
> +#define assert(X) do { if (!(X)) __builtin_abort(); } while(0)
> +
> +void f(){}
> +void g(){}
> +
> +int main()
> +{
> +  {
> +const auto v =  <=> // { dg-error "invalid operands" }
...

I've noticed this test being UNRESOLVED (the execution part of it, because
we expect errors during compilation).

Fixed thusly, tested on x86_64-linux, committed to trunk as obvious:

2019-11-08  Jakub Jelinek  

* g++.dg/cpp2a/spaceship-scalar1-neg.C: Change dg-do from run to
compile.

--- gcc/testsuite/g++.dg/cpp2a/spaceship-scalar1-neg.C  (revision 277932)
+++ gcc/testsuite/g++.dg/cpp2a/spaceship-scalar1-neg.C  (working copy)
@@ -1,4 +1,4 @@
-// { dg-do run { target c++2a } }
+// { dg-do compile { target c++2a } }
 
 #include 
 


Jakub



[C++ PATCH] Implement D1959R0, remove weak_equality and strong_equality.

2019-11-07 Thread Jason Merrill
Shortly after I finished implementing the previous <=> semantics, the
committee decided to remove the *_equality comparison categories, because
they were largely obsoleted by the earlier change that separated operator==
from its original dependency on operator<=>.

Tested x86_64-pc-linux-gnu, applying to trunk.

gcc/cp/
* method.c (enum comp_cat_tag, comp_cat_info): Remove *_equality.
(genericize_spaceship, common_comparison_type): Likewise.
* typeck.c (cp_build_binary_op): Move SPACESHIP_EXPR to be with the
relational operators, exclude other types no longer supported.
libstdc++-v3/
* libsupc++/compare: Remove strong_equality and weak_equality.
---
 gcc/cp/method.c   |  47 +-
 gcc/cp/typeck.c   |  13 +-
 .../g++.dg/cpp2a/spaceship-scalar1-neg.C  |  25 
 .../g++.dg/cpp2a/spaceship-scalar1.C  |  27 
 .../g++.dg/cpp2a/spaceship-scalar1a.C |  12 --
 .../g++.dg/cpp2a/spaceship-scalar3.C  |  18 +--
 libstdc++-v3/libsupc++/compare| 136 +-
 7 files changed, 44 insertions(+), 234 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/spaceship-scalar1-neg.C

diff --git a/gcc/cp/method.c b/gcc/cp/method.c
index c9dd90fcba7..47441c10c52 100644
--- a/gcc/cp/method.c
+++ b/gcc/cp/method.c
@@ -882,8 +882,6 @@ do_build_copy_assign (tree fndecl)
 
 enum comp_cat_tag
 {
-  cc_weak_equality,
-  cc_strong_equality,
   cc_partial_ordering,
   cc_weak_ordering,
   cc_strong_ordering,
@@ -901,8 +899,6 @@ struct comp_cat_info_t
 };
 static const comp_cat_info_t comp_cat_info[cc_last]
 = {
-   { "weak_equality", "equivalent", "nonequivalent" },
-   { "strong_equality", "equal", "nonequal" },
{ "partial_ordering", "equivalent", "greater", "less", "unordered" },
{ "weak_ordering", "equivalent", "greater", "less" },
{ "strong_ordering", "equal", "greater", "less" }
@@ -1028,21 +1024,8 @@ spaceship_comp_cat (tree optype)
 return cc_strong_ordering;
   else if (TREE_CODE (optype) == REAL_TYPE)
 return cc_partial_ordering;
-  else if (TYPE_PTRFN_P (optype) || TYPE_PTRMEM_P (optype)
-  || NULLPTR_TYPE_P (optype))
-return cc_strong_equality;
-  else if (TREE_CODE (optype) == COMPLEX_TYPE)
-{
-  tree intype = optype;
-  while (TREE_CODE (intype) == COMPLEX_TYPE)
-   intype = TREE_TYPE (intype);
-  if (TREE_CODE (intype) == REAL_TYPE)
-   return cc_weak_equality;
-  else
-   return cc_strong_equality;
-}
 
-  /* FIXME should vector <=> produce a vector of one of the above?  */
+  /* ??? should vector <=> produce a vector of one of the above?  */
   gcc_unreachable ();
 }
 
@@ -1065,35 +1048,29 @@ genericize_spaceship (tree type, tree op0, tree op1)
   comp_cat_tag tag = cat_tag_for (type);
   gcc_checking_assert (tag < cc_last);
 
-  tree eq = lookup_comparison_result (tag, type, 0);
-  tree negt = lookup_comparison_result (tag, type, 1);
-
-  if (tag == cc_strong_equality || tag == cc_weak_equality)
-{
-  tree comp = fold_build2 (EQ_EXPR, boolean_type_node, op0, op1);
-  return fold_build3 (COND_EXPR, type, comp, eq, negt);
-}
-
   tree r;
   op0 = save_expr (op0);
   op1 = save_expr (op1);
 
+  tree gt = lookup_comparison_result (tag, type, 1);
+
   if (tag == cc_partial_ordering)
 {
   /* op0 == op1 ? equivalent : op0 < op1 ? less :
 op0 > op1 ? greater : unordered */
   tree uo = lookup_comparison_result (tag, type, 3);
   tree comp = fold_build2 (GT_EXPR, boolean_type_node, op0, op1);
-  r = fold_build3 (COND_EXPR, type, comp, negt, uo);
+  r = fold_build3 (COND_EXPR, type, comp, gt, uo);
 }
   else
 /* op0 == op1 ? equal : op0 < op1 ? less : greater */
-r = negt;
+r = gt;
 
   tree lt = lookup_comparison_result (tag, type, 2);
   tree comp = fold_build2 (LT_EXPR, boolean_type_node, op0, op1);
   r = fold_build3 (COND_EXPR, type, comp, lt, r);
 
+  tree eq = lookup_comparison_result (tag, type, 0);
   comp = fold_build2 (EQ_EXPR, boolean_type_node, op0, op1);
   r = fold_build3 (COND_EXPR, type, comp, eq, r);
 
@@ -1178,18 +1155,6 @@ common_comparison_type (vec )
return void_type_node;
 }
 
-  /* Otherwise, if at least one T i is std::weak_equality, or at least one T i
- is std::strong_equality and at least one T j is std::partial_ordering or
- std::weak_ordering, U is std::weak_equality.  */
-  if (tree t = seen[cc_weak_equality]) return t;
-  if (seen[cc_strong_equality]
-  && (seen[cc_partial_ordering] || seen[cc_weak_ordering]))
-return lookup_comparison_category (cc_weak_equality);
-
-  /* Otherwise, if at least one T i is std::strong_equality, U is
- std::strong_equality.  */
-  if (tree t = seen[cc_strong_equality]) return t;
-
   /* Otherwise, if at least one T i is std::partial_ordering, U is
  std::partial_ordering.  */
   if (tree t = seen[cc_partial_ordering]) return t;
diff --git