aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2021-09-30 17:29:05 -0400
committerPatrick Palka <ppalka@redhat.com>2021-09-30 17:29:05 -0400
commitb6bca2e631b54f992c058ca8e445b45e9816690b (patch)
treeac911b7f42efb7d6176ed747a1a2ed699a7a7937
parentbffb580d6f0e8b6f9623128d38ea653a99a58d49 (diff)
downloadgcc-b6bca2e631b54f992c058ca8e445b45e9816690b.zip
gcc-b6bca2e631b54f992c058ca8e445b45e9816690b.tar.gz
gcc-b6bca2e631b54f992c058ca8e445b45e9816690b.tar.bz2
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.
-rw-r--r--gcc/cp/method.c4
-rw-r--r--gcc/testsuite/g++.dg/cpp2a/spaceship-virtual1.C20
2 files changed, 24 insertions, 0 deletions
diff --git a/gcc/cp/method.c b/gcc/cp/method.c
index 32f7186..3c34952 100644
--- a/gcc/cp/method.c
+++ b/gcc/cp/method.c
@@ -1426,6 +1426,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 0000000..8067d3c
--- /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();
+}