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

--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-16 branch has been updated by Patrick Palka
<[email protected]>:

https://gcc.gnu.org/g:54cdaf3248635d66d13597e00e3c285b1cc17112

commit r16-8838-g54cdaf3248635d66d13597e00e3c285b1cc17112
Author: Patrick Palka <[email protected]>
Date:   Thu Apr 23 18:31:53 2026 -0400

    c++/modules: PTRMEM_CST member considered unused [PR124981]

    Here in _b.C the needed specialization A<B, &B::g> has already been
    instantiated in module M, so we stream it in rather than instantiate it.
    We then proceed to instantiate A<B, &B::g>::f() whose definition invokes
    the pointer-to-member &B::g but it turns out that nothing has marked
    B::g as used in this TU so we neglect to emit it and linking fails.

    We do mark B::g as used during instantiation of A<B, &B::g> via
    mark_template_arguments_used, but this instantiaton happens in module M
    not the importer, and TREE_USED is deliberately not streamed.

    This patch fixes this by setting TREE_USED on PTRMEM_CST_MEMBER during
    stream-in, via the RTU macro, which seems sufficient to ensure B::g gets
    emitted.  This macro is already used for streaming in subexpressions and
    BASELINK_FUNCTIONS so using it for PTRMEM_CST_MEMBER doesn't seem too
    out of place.

            PR c++/124981

    gcc/cp/ChangeLog:

            * module.cc (trees_in::core_vals) <case PTRMEM_CST>: Use RTU
            instead of RT to stream PTRMEM_CST_MEMBER.

    gcc/testsuite/ChangeLog:

            * g++.dg/modules/ptrmem-1_a.C: New test.
            * g++.dg/modules/ptrmem-1_b.C: New test.

    Reviewed-by: Jason Merrill <[email protected]>
    (cherry picked from commit 043ec576719d8cea9506ece0e211169c61fae242)
  • [Bug c++/124981] [modules] Unde... cvs-commit at gcc dot gnu.org via Gcc-bugs

Reply via email to