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

--- 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:e9e3383f86425f10d3a9bd4daac6e62e8f8176f0

commit r16-6853-ge9e3383f86425f10d3a9bd4daac6e62e8f8176f0
Author: Nathaniel Shead <[email protected]>
Date:   Sat Jan 17 10:41:58 2026 +1100

    c++/modules: Fix local type handling when not streaming function
definitions [PR123627]

    r14-9948-g716af95fd45487 added support for merging local types of
    functions.  This however causes the linked PR to crash, because when
    restreaming the local type from a partition for the primary module
    interface's CMI, we no longer have the DECL_INITIAL for a function.

    This patch fixes the issue by reusing the MK_keyed merge kind, as used
    for lambda types.  This is required so that if a module partition
    imports both the primary module interface and a different module
    partition that both provide the same local type it can properly dedup
    the declarations.

    We only need to do this if !has_definition; in cases where a definition
    is available we keep using the MK_local_type behaviour as that avoids
    the need to maintain a separately allocated chain of keyed decls.

    An additional change is to further the modifications made in r16-4671
    and always attempt to key to the top-most decl, including going through
    possibly many nested class and function definitions.  This avoids any
    similar issues to that bug where we read a keyed decl before we see the
    decl it's keyed to now that we support keying to functions as well.

            PR c++/123627

    gcc/cp/ChangeLog:

            * class.cc (finish_struct): Maybe key function-local types.
            * module.cc (trees_out::get_merge_kind): Choose whether to use
            MK_local_type or MK_keyed for a local type based on if the
            immediate context's definition will be streamed.
            (trees_in::key_mergeable): Allow key decls on FUNCTION_DECL.
            (adjust_key_scope): New function.
            (maybe_key_decl): Handle key decls on FUNCTION_DECL; check that
            we only key a given decl to a context at most once.
            (get_keyed_decl_scope): Support non-lambda decls.

    gcc/testsuite/ChangeLog:

            * g++.dg/modules/block-decl-4_a.C: New test.
            * g++.dg/modules/block-decl-4_b.C: New test.
            * g++.dg/modules/block-decl-4_c.C: New test.

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

Reply via email to