From: Jason Merrill Date: Mon, 18 Dec 2023 20:47:10 +0000 (-0500) Subject: c++: __class_type_info and modules [PR113038] X-Git-Tag: basepoints/gcc-15~2926 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=27521a2f4f7b859d5656e5bdd69d3f759ea4c23a;p=thirdparty%2Fgcc.git c++: __class_type_info and modules [PR113038] Doing a dynamic_cast in both TUs broke because we were declaring a new __class_type_info in _b that conflicted with the one imported in the global module from _a. It seems clear to me that any new class declaration in the global module should merge with an imported definition, but for GCC 14 let's just fix this for the specific case of __class_type_info. PR c++/113038 gcc/cp/ChangeLog: * name-lookup.cc (lookup_elaborated_type): Look for bindings in the global namespace in the ABI namespace. gcc/testsuite/ChangeLog: * g++.dg/modules/pr106304_b.C: Add dynamic_cast. --- diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc index 26c6bc71e993..d827d337d3bb 100644 --- a/gcc/cp/name-lookup.cc +++ b/gcc/cp/name-lookup.cc @@ -8089,9 +8089,19 @@ lookup_elaborated_type (tree name, TAG_how how) { /* We're in the global module, perhaps there's a tag there? */ - // FIXME: This isn't quite right, if we find something - // here, from the language PoV we're not supposed to - // know it? + + /* FIXME: In general we should probably merge global module + classes in check_module_override rather than here, but for + GCC14 let's just fix lazy declarations of __class_type_info in + build_dynamic_cast_1. */ + if (current_namespace == abi_node) + { + tree g = (BINDING_VECTOR_CLUSTER (*slot, 0) + .slots[BINDING_SLOT_GLOBAL]); + for (ovl_iterator iter (g); iter; ++iter) + if (qualify_lookup (*iter, LOOK_want::TYPE)) + return *iter; + } } } } diff --git a/gcc/testsuite/g++.dg/modules/pr106304_b.C b/gcc/testsuite/g++.dg/modules/pr106304_b.C index e8333909c8de..0d1da0861769 100644 --- a/gcc/testsuite/g++.dg/modules/pr106304_b.C +++ b/gcc/testsuite/g++.dg/modules/pr106304_b.C @@ -5,4 +5,5 @@ module pr106304; void f(A& a) { as_b(a); + dynamic_cast(&a); }