On 10/6/21 05:06, Jakub Jelinek wrote:
On Tue, Oct 05, 2021 at 10:40:45PM -0400, Jason Merrill wrote:
I've switched to handling bases via binfo as discussed on IRC and added
spaceship-synth14.C to test proper base handling with virtual <=>. Here's
what I'm committing:
Thanks a lot.
I see spaceship-synth8.C is accepted without errors (| LOOKUP_NONVIRTUAL |
LOOKUP_DEFAULTED didn't help it for me back when playing with it), but if I add
E e1, e2;
auto x = e1 <=> e2;
at the end of it, it is rejected:
spaceship-synth8.C:26:17: error: use of deleted function ‘virtual constexpr
std::strong_ordering E::operator<=>(const E&) const’
26 | auto x = e1 <=> e2;
| ^~
spaceship-synth8.C:22:24: note: ‘virtual constexpr std::strong_ordering
E::operator<=>(const E&) const’ is implicitly deleted because the default
definition would be ill-formed:
22 | std::strong_ordering operator<=>(const E&) const override = default;
| ^~~~~~~~
spaceship-synth8.C:21:8: error: no match for ‘operator<=>’ (operand types are
‘const D’ and ‘const D’)
21 | struct E : D {
| ^
spaceship-synth8.C:19:32: note: candidate: ‘virtual std::strong_ordering
D::operator<=>(const E&) const’ (reversed)
19 | virtual std::strong_ordering operator<=>(const struct E&) const = 0;
| ^~~~~~~~
spaceship-synth8.C:19:44: note: no known conversion for argument 1 from ‘const D’
to ‘const E&’
19 | virtual std::strong_ordering operator<=>(const struct E&) const = 0;
| ^~~~~~~~~~~~~~~
Is that ok (i.e. whether it is accepted or rejected when the operator<=>
is actually not called falls into "no diagnostics required" category)?
It's not even NDR, it's implicitly deleted, so it's well-formed until
called.
Note, before this fix we were accepting it even with those
E e1, e2;
auto x = e1 <=> e2;
lines in there. Perhaps we want to copy spaceship-synth8.C to another
test that will add those two lines and check for the errors...
Done:
From 15b57c0ffe8ac9d568e76e70244cf723b72b1a82 Mon Sep 17 00:00:00 2001
From: Jason Merrill <ja...@redhat.com>
Date: Wed, 6 Oct 2021 17:12:02 -0400
Subject: [PATCH] c++: One more spaceship test.
To: gcc-patches@gcc.gnu.org
Jakub suggested adding a variant where we actually try to call the
implicitly deleted operator.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/spaceship-synth8a.C: New test.
---
.../g++.dg/cpp2a/spaceship-synth8a.C | 25 +++++++++++++++++++
1 file changed, 25 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/cpp2a/spaceship-synth8a.C
diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-synth8a.C b/gcc/testsuite/g++.dg/cpp2a/spaceship-synth8a.C
new file mode 100644
index 00000000000..42a32da77f9
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/spaceship-synth8a.C
@@ -0,0 +1,25 @@
+// PR c++/94907
+// { dg-do compile { target c++20 } }
+
+namespace std { struct strong_ordering {
+ int _v;
+ constexpr strong_ordering (int v) :_v(v) {}
+ constexpr operator int (void) const { return _v; }
+ static const strong_ordering less;
+ static const strong_ordering equal;
+ static const strong_ordering greater;
+};
+constexpr strong_ordering strong_ordering::less = -1;
+constexpr strong_ordering strong_ordering::equal = 0;
+constexpr strong_ordering strong_ordering::greater = 1;
+}
+
+struct E;
+struct D {
+ virtual std::strong_ordering operator<=>(const struct E&) const = 0;
+};
+struct E : D { // { dg-error "no match" }
+ std::strong_ordering operator<=>(const E&) const override = default; // { dg-message "default" }
+};
+
+auto x = E() <=> E(); // { dg-error "deleted" }
--
2.27.0