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

--- Comment #2 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:c4845edfeaf44756ad9672e8d143f1c8f5c4c0f6

commit r14-9530-gc4845edfeaf44756ad9672e8d143f1c8f5c4c0f6
Author: Nathaniel Shead <nathanielosh...@gmail.com>
Date:   Sat Mar 16 22:00:29 2024 +1100

    c++: Fix handling of no-linkage decls for modules

    When testing the changes for PR c++/112631 we discovered that currently
    we don't emit definitions of block-scope function declarations if
    they're not used in the module interface TU, which causes issues if they
    are used by importers.

    This patch fixes the handling of no-linkage declarations for C++20. In
    particular, a type declared in a function with vague linkage or declared
    in a module CMI could potentially be accessible outside its defining TU,
    and as such we can't assume that function declarations using that type
    can never be defined in another TU.

    A complication with handling this is that we're only strictly interested
    in declarations with a module CMI, but when parsing the global module
    fragment we don't yet know whether or not this module will have a CMI
    until we reach the "export module" line (or not). Since this case is
    IFNDR anyway (by [basic.def.odr] p11) we just tentatively assume while
    parsing the GMF that this module will have a CMI; once we see (or don't
    see) an 'export module' declaration we can commit to that knowledge for
    future declarations.

    gcc/cp/ChangeLog:

            * cp-tree.h (module_maybe_has_cmi_p): New function.
            * decl.cc (grokfndecl): Mark block-scope functions as public if
            they could be visible in other TUs.
            * decl2.cc (no_linkage_error): Don't error for declarations that
            could be defined in other TUs since C++20. Suppress duplicate
            errors from 'check_global_declaration'.
            * tree.cc (no_linkage_check): In relaxed mode, don't consider
            types in a module CMI to have no linkage.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp2a/linkage-1.C: New test.
            * g++.dg/modules/block-decl-3.h: New test.
            * g++.dg/modules/block-decl-3_a.C: New test.
            * g++.dg/modules/block-decl-3_b.C: New test.
            * g++.dg/modules/block-decl-3_c.C: New test.
            * g++.dg/modules/linkage-1_a.C: New test.
            * g++.dg/modules/linkage-1_b.C: New test.
            * g++.dg/modules/linkage-1_c.C: New test.
            * g++.dg/modules/linkage-2.C: New test.

    Signed-off-by: Nathaniel Shead <nathanielosh...@gmail.com>
    Reviewed-by: Jason Merrill <ja...@redhat.com>
  • [Bug c++/112631] gcc rejects bl... cvs-commit at gcc dot gnu.org via Gcc-bugs

Reply via email to