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

--- Comment #1 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Nathaniel Shead <nsh...@gcc.gnu.org>:

https://gcc.gnu.org/g:9016c5ac94c55714d001309ef640710f9d512254

commit r15-6378-g9016c5ac94c55714d001309ef640710f9d512254
Author: Nathaniel Shead <nathanielosh...@gmail.com>
Date:   Tue Oct 8 20:50:38 2024 +1100

    c++/modules: Detect exposures of TU-local entities

    Currently, the modules streaming code implements some checks for
    declarations in the CMI that reference (some kinds of) internal-linkage
    entities, and errors if so.  This patch expands on that support to
    implement the logic for exposures of TU-local entities as defined in
    [basic.link] since P1815.

    This will cause some code that previously errored in modules to start
    compiling; for instance, template specialisations of internal linkage
    functions.

    However, some code that previously appeared valid will with this patch
    no longer compile, notably some kinds of usages of internal linkage
    functions included from the GMF.  This appears to be related to P2808
    and FR-025, however as yet there doesn't appear to be consensus for
    changing these rules so I've implemented them as-is.

    This patch leaves a couple of things out.  In particular, a couple of
    the rules for what is a TU-local entity currently seem to me to be
    redundant; I've left them as FIXMEs to be handled once I can find
    testcases that aren't adequately supported by the other logic here.

    Additionally, there are some exceptions for when naming a TU-local
    entity is not always an exposure; I've left support for this to a
    follow-up patch for easier review, as it has broader implications for
    streaming.

    TU-local lambdas are also not yet properly implemented, due to other
    bugs with regards to LAMBDA_TYPE_EXTRA_SCOPE not being set in all cases
    that it probably should be (see also PR c++/116568).  We can revisit
    this once that issue has been fixed.

    Finally, this patch makes a couple of small adjustments to the modules
    streaming logic to prune any leftover TU-local deps (that aren't
    erroneous exposures).  This is required for this patch to ensure that
    later stages don't get confused by any leftover TU-local entities
    floating around.

    gcc/cp/ChangeLog:

            * tree.cc (decl_linkage): Treat DECL_SELF_REFERENCE_P like
            DECL_IMPLICIT_TYPEDEF_P.
            * name-lookup.cc (do_namespace_alias): Fix linkage.
            * module.cc (DB_IS_INTERNAL_BIT): Rename to...
            (DB_TU_LOCAL_BIT): ...this.
            (DB_REFS_INTERNAL_BIT): Rename to...
            (DB_EXPOSURE_BIT): ...this.
            (depset::hash::is_internal): Rename to...
            (depset::hash::is_tu_local): ...this.
            (depset::hash::refs_internal): Rename to...
            (depset::hash::is_exposure): ...this.
            (depset::hash::is_tu_local_entity): New function.
            (depset::hash::has_tu_local_tmpl_arg): New function.
            (depset::hash::is_tu_local_value): New function.
            (depset::hash::make_dependency): Check for TU-local entities.
            (depset::hash::add_dependency): Make current an exposure
            whenever it references a TU-local entity.
            (depset::hash::add_binding_entity): Don't create bindings for
            any TU-local entity.
            (depset::hash::finalize_dependencies): Rename flags and adjust
            diagnostic messages to report exposures of TU-local entities.
            (depset::tarjan::connect): Don't include any TU-local depsets.
            (depset::hash::connect): Likewise.

    gcc/testsuite/ChangeLog:

            * g++.dg/modules/block-decl-2.C: Adjust messages.
            * g++.dg/modules/internal-1.C: Adjust messages, remove XFAILs.
            * g++.dg/modules/linkage-2.C: Adjust messages, remove XFAILS.
            * g++.dg/modules/internal-3.C: New test.
            * g++.dg/modules/internal-4_a.H: New test.
            * g++.dg/modules/internal-4_b.C: New test.

    Signed-off-by: Nathaniel Shead <nathanielosh...@gmail.com>
    Reviewed-by: Jason Merrill <ja...@redhat.com>

Reply via email to