]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: __class_type_info and modules [PR113038]
authorJason Merrill <jason@redhat.com>
Mon, 18 Dec 2023 20:47:10 +0000 (15:47 -0500)
committerJason Merrill <jason@redhat.com>
Fri, 12 Jan 2024 17:14:36 +0000 (12:14 -0500)
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.

gcc/cp/name-lookup.cc
gcc/testsuite/g++.dg/modules/pr106304_b.C

index 26c6bc71e9932a0a7acc00f99349bd087202e9a1..d827d337d3bbce0b118dd7e449aa3293b95832d0 100644 (file)
@@ -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;
+               }
            }
        }
     }
index e8333909c8de27ba064ac924f0837ccfcaa447b8..0d1da0861769a44e6ce9973f8b4273d7cbf4230a 100644 (file)
@@ -5,4 +5,5 @@ module pr106304;
 
 void f(A& a) {
   as_b(a);
+  dynamic_cast<B*>(&a);
 }