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>
}
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. */
--- /dev/null
+// { 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]);