https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124485

--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Nathaniel Shead <[email protected]>:

https://gcc.gnu.org/g:8c45800ed688fc31fccee49fb1c5c51157be8c89

commit r16-8092-g8c45800ed688fc31fccee49fb1c5c51157be8c89
Author: Nathaniel Shead <[email protected]>
Date:   Sat Mar 14 11:25:47 2026 +1100

    c++/modules: Fix crash on implicit redeclaration of ABI class types
[PR124485]

    The crash in the given testcase occurs because the fix for PR122053,
    r16-4228-gfa6544ef5f50a824cabeda4906453d4545fbf66f, added a call to
    lazy_load_pending when doing push_tag, to prevent ICEs at least when
    types are textually redefined in lieu of full PR99000 support.

    But this means that we might not have loaded the declarations of the ABI
    types in lookup_elaborated_type to merge them there yet, but still have
    them by the time we get to check_module_override, causing errors, and
    then an ICE because tinfo_base_init is not prepared for xref_tag to
    fail.

    It turns out that doing the lazy load in pushtag is too late; we replace
    the decl, but we don't replace the type, and then we end up returning
    the type that we were building anyway rather than the type we were
    hoping to match against.

    The reason I'd done it there originally is because that's the earliest
    we have a decl to do lazy_load_pendings with, but it seems that instead
    we should have another interface to lazy_load_pendings that can be used
    if you already know the name and namespace of the entity that you're
    keying too.

            PR c++/124485

    gcc/cp/ChangeLog:

            * cp-tree.h (lazy_load_pendings): Declare new overload.
            * module.cc (lazy_load_pendings): Define it.
            * name-lookup.cc (lookup_elaborated_type): Load pending entities
            with given name before doing namespace-scope lookup.
            (pushtag): Remove no-longer-needed pending load.

    gcc/testsuite/ChangeLog:

            * g++.dg/modules/class-8_b.C: Adjusted expected behaviour.
            * g++.dg/modules/pr124485_a.C: New test.
            * g++.dg/modules/pr124485_b.C: New test.

    Signed-off-by: Nathaniel Shead <[email protected]>
    Reviewed-by: Jason Merrill <[email protected]>

Reply via email to