public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-9084] c++: defaulted comparisons and vptr fields [PR95567]
@ 2021-10-06 14:15 Patrick Palka
0 siblings, 0 replies; only message in thread
From: Patrick Palka @ 2021-10-06 14:15 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:e84436a273f0fbb42b9785ff5bb1deaf9a500f37
commit r11-9084-ge84436a273f0fbb42b9785ff5bb1deaf9a500f37
Author: Patrick Palka <ppalka@redhat.com>
Date: Thu Sep 30 17:29:05 2021 -0400
c++: defaulted comparisons and vptr fields [PR95567]
We need to explicitly skip over vptr fields when synthesizing a
defaulted comparison operator, because next_initializable_field
doesn't do so for us.
PR c++/95567
gcc/cp/ChangeLog:
* method.c (build_comparison_op): Skip DECL_VIRTUAL_P fields.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/spaceship-virtual1.C: New test.
(cherry picked from commit b6bca2e631b54f992c058ca8e445b45e9816690b)
Diff:
---
gcc/cp/method.c | 4 ++++
gcc/testsuite/g++.dg/cpp2a/spaceship-virtual1.C | 20 ++++++++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/gcc/cp/method.c b/gcc/cp/method.c
index b82aeefa6ab..8d2f3ce30af 100644
--- a/gcc/cp/method.c
+++ b/gcc/cp/method.c
@@ -1424,6 +1424,10 @@ build_comparison_op (tree fndecl, tsubst_flags_t complain)
field;
field = next_initializable_field (DECL_CHAIN (field)))
{
+ if (DECL_VIRTUAL_P (field))
+ /* Don't compare vptr fields. */
+ continue;
+
tree expr_type = TREE_TYPE (field);
location_t field_loc = DECL_SOURCE_LOCATION (field);
diff --git a/gcc/testsuite/g++.dg/cpp2a/spaceship-virtual1.C b/gcc/testsuite/g++.dg/cpp2a/spaceship-virtual1.C
new file mode 100644
index 00000000000..8067d3cd9d1
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/spaceship-virtual1.C
@@ -0,0 +1,20 @@
+// PR c++/95567
+// { dg-do run { target c++20 } }
+
+struct B {
+ B(int i) : i(i) {}
+ virtual ~B() = default;
+
+ bool operator==(B const&) const = default;
+ int i;
+};
+
+struct D : B {
+ D(int i, int j) : B(i), j(j) {}
+ int j;
+};
+
+int main() {
+ if (B(2) != D(2, 3))
+ __builtin_abort();
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-10-06 14:15 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-06 14:15 [gcc r11-9084] c++: defaulted comparisons and vptr fields [PR95567] Patrick Palka
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).