From: Jakub Jelinek Date: Wed, 29 Apr 2026 06:01:02 +0000 (+0200) Subject: c++: Fix up REFLECT_BASE comparison X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bc01d2d759285a992076544457ad284bb48632ef;p=thirdparty%2Fgcc.git c++: Fix up REFLECT_BASE comparison 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 * 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 --- diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc index 6ef718e560f..c6b0f6f2bd1 100644 --- a/gcc/cp/reflect.cc +++ b/gcc/cp/reflect.cc @@ -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 index 00000000000..9c6e038ed1d --- /dev/null +++ b/gcc/testsuite/g++.dg/reflect/compare12.C @@ -0,0 +1,12 @@ +// { dg-do compile { target c++26 } } +// { dg-additional-options "-freflection" } + +#include + +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]);