[Bug c++/114450] -Wunused-but-set-variable false positive of static variable initialized by a lambda used by a generic lambda

cvs-commit at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Jan 28 02:33:17 GMT 2026


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

--- Comment #8 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:04ec3d4712519e32f85c034ff4237fcd5f9fbe39

commit r16-7094-g04ec3d4712519e32f85c034ff4237fcd5f9fbe39
Author: Lucas Chollet <lucas.chollet@free.fr>
Date:   Mon Jan 26 18:16:53 2026 +0800

    c++: Fix false positive with -Wunused [PR114450]

    The patch fixes a bug in the detection of the usage of static variables
    inside generic lambdas.  The comment in finish_id_expression_1 already
    mentions this case, but the code didn't actually handle it.

            PR c++/114450

    gcc/cp/ChangeLog:

            * lambda.cc (generic_lambda_fn_p): Handle null argument.
            * semantics.cc (finish_id_expression_1): Check for generic lambda.

    gcc/testsuite/ChangeLog:

            * g++.dg/warn/Wunused-var-42.C: New test.

    Co-authored-by: Jason Merrill <jason@redhat.com>


More information about the Gcc-bugs mailing list