]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++/reflection: fixes for comparing reflections [PR125208]
authorMarek Polacek <polacek@redhat.com>
Thu, 7 May 2026 20:38:34 +0000 (16:38 -0400)
committerMarek Polacek <polacek@redhat.com>
Tue, 12 May 2026 00:32:42 +0000 (20:32 -0400)
commit7199cf12773b1429c19cdd5b69950b2f09470e64
tree12b50e4ad908e7c53f9fa71d81dbdd8ed80c9b44
parent03894dd6c6ec8bcfab6c9058c22f88691a2e7711
c++/reflection: fixes for comparing reflections [PR125208]

This fixes two bugs:

1) crash in cp_tree_equal when comparing reflections with binfos;
cp_tree_equal doesn't handle those.  We're coming from
lookup_template_class -> spec_hasher::equal -> comp_template_args
-> cp_tree_equal.  We should use compare_reflections in cp_tree_equal.

2) the fix for 1) revealed that compare_reflections is buggy when
comparing two aliases: we shouldn't fall back to same_type_p
because given

   using A = int;
   using B = int;

^^A != ^^B should hold.

PR c++/125208

gcc/cp/ChangeLog:

* reflect.cc (compare_reflections): Use == when comparing two
aliases.
* tree.cc (cp_tree_equal) <case REFLECT_EXPR>: Use
compare_reflections.

gcc/testsuite/ChangeLog:

* g++.dg/reflect/alias3.C: New test.
* g++.dg/reflect/bases_of5.C: New test.

Reviewed-by: Patrick Palka <ppalka@redhat.com>
gcc/cp/reflect.cc
gcc/cp/tree.cc
gcc/testsuite/g++.dg/reflect/alias3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/reflect/bases_of5.C [new file with mode: 0644]