]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Fix up REFLECT_BASE comparison
authorJakub Jelinek <jakub@redhat.com>
Wed, 29 Apr 2026 06:01:02 +0000 (08:01 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 29 Apr 2026 06:01:02 +0000 (08:01 +0200)
While writing testcase for PR125007 I found an ICE in cp_tree_equal.
The r16-7260 change to compare_reflections broke REFLECT_BASE comparisons.
It now calls cp_tree_equal on their REFLECT_EXPR_HANDLE which is TREE_BINFO.
It works if lhs == rhs, returns true, or if TREE_CODE is different (returns
false), but otherwise the function isn't prepared to handle TREE_BINFO
and because TREE_BINFO is tcc_exceptional, ends with
     default:
       gcc_unreachable ();
(for --disable-checking it actually works by doing return false; after
this).  This patch fixes that in the third hunk by doing lhs == rhs
comparison only.

2026-04-29  Jakub Jelinek  <jakub@redhat.com>

* reflect.cc (compare_reflection): For REFLECT_BASE use lhs == rhs rather
than cp_tree_equal.

* g++.dg/reflect/compare12.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/reflect.cc
gcc/testsuite/g++.dg/reflect/compare12.C [new file with mode: 0644]

index 6ef718e560fc3778c12b6bbf8ce4d93604acaf91..c6b0f6f2bd1a46a2ac72d02f56f519e22bc4850c 100644 (file)
@@ -8872,6 +8872,8 @@ compare_reflections (tree lhs, tree rhs)
     }
   else if (lkind == REFLECT_ANNOTATION)
     return TREE_VALUE (lhs) == TREE_VALUE (rhs);
+  else if (lkind == REFLECT_BASE)
+    return lhs == rhs;
   else if (TYPE_P (lhs) && TYPE_P (rhs))
     {
       /* Given "using A = int;", "^^int != ^^A" should hold.  */
diff --git a/gcc/testsuite/g++.dg/reflect/compare12.C b/gcc/testsuite/g++.dg/reflect/compare12.C
new file mode 100644 (file)
index 0000000..9c6e038
--- /dev/null
@@ -0,0 +1,12 @@
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+
+#include <meta>
+
+struct A {};
+struct B {};
+struct C : A, B {};
+struct D : A, B {};
+constexpr auto ctx = std::meta::access_context::unchecked ();
+static_assert (bases_of (^^C, ctx)[0] != bases_of (^^C, ctx)[1]);
+static_assert (bases_of (^^C, ctx)[1] != bases_of (^^D, ctx)[1]);