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

--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Jason Merrill <[email protected]>:

https://gcc.gnu.org/g:97bcbeb6e12d644442f69bca09110c5392584460

commit r17-5384-g97bcbeb6e12d644442f69bca09110c5392584460
Author: Shubham Nayak <[email protected]>
Date:   Tue Oct 20 01:36:00 2026 +0530

    c++: remove redundant lvalue check for reference captures [PR87638]

    In add_capture, reference captures were unconditionally rejected
    whenever !lvalue_p (initializer) was true. This check predates
    C++14 init-captures and is redundant with build_lambda_object,
    which already validates the initialization of each capture field
    via finish_compound_literal and initialize_reference.

    Even worse was that checking !lvalue_p in add_capture rejects
    valid C++14 reference init-captures which are:

    1. reference init-captures bound to const xvalues or const
    class prvalues, where auto deduction yields 'const T&'
    ([expr.prim.lambda.capture] p6, [dcl.init.ref] p5).

    2. direct-list-initialized reference init-captures (per
    [expr.prim.lambda.capture] p6) where initializer is a
    CONSTRUCTOR node and hence not an lvalue.

    Remove the redundant check in add_capture and let
    build_lambda_object diagnose invalid reference bindings.

    This patch has been regtested on x86_64-pc-linux-gnu.

            PR c++/87638
            PR c++/90789
            PR c++/95069
            PR c++/104411
            PR c++/115471

    gcc/cp/ChangeLog:

            * lambda.cc (add_capture): Remove redundant
            !lvalue_p check on reference captures.

    gcc/testsuite/ChangeLog:

            * g++.dg/cpp1y/lambda-init-const-ref.C: New test.
            * g++.dg/cpp1y/lambda-init21.C: New test.

    Signed-off-by: Shubham Nayak <[email protected]>

Reply via email to