[Bug c++/124483] [[maybe_unused]] is not honoured in a templated class within a C++ module

cvs-commit at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Sat Mar 21 00:22:08 GMT 2026


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

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

https://gcc.gnu.org/g:e20b3ae5e7cdda45582fa09b7dc9c7840ed8f079

commit r16-8241-ge20b3ae5e7cdda45582fa09b7dc9c7840ed8f079
Author: Nathaniel Shead <nathanieloshead@gmail.com>
Date:   Thu Mar 19 22:56:20 2026 +1100

    c++/modules: Handle maybe_unused on PARM_DECLs [PR124483]

    The [[maybe_unused]] attribute works by marking relevant entities as
    TREE_USED, and DECL_READ_P for vars and parms.  But modules streaming
    typically clears this flag unless reading a definition.  This patch sets
    it back again when we see this attribute applied to a parameter.

            PR c++/124483

    gcc/cp/ChangeLog:

            * module.cc (trees_in::fn_parms_init): Set TREE_USED and
            DECL_READ_P for parameters deliberately marked unused.

    gcc/testsuite/ChangeLog:

            * g++.dg/modules/attrib-4_a.C: New test.
            * g++.dg/modules/attrib-4_b.C: New test.

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


More information about the Gcc-bugs mailing list