GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
c++

C++: Remove redundant lvalue check for reference captures

Fixes C++ lambda reference captures by removing an erroneous check.

This commit removes a redundant lvalue check in GCC’s C++ lambda reference capture handling. The previous check incorrectly rejected valid C++14 init-captures, including those bound to const lvalues and direct-list-initialized references. The validation is now correctly delegated to the build_lambda_object function.

In Details

The add_capture function in gcc/cp/lambda.cc previously performed an unnecessary !lvalue_p check on initializers for reference captures. This commit removes that check, resolving issues with C++14 init-captures of const xvalues/prvalues and direct-list-initialized references. The validation responsibility is now solely with build_lambda_object.

For Context
lvalue
An expression that refers to a memory location, which can be the target of an assignment or address-of operation.
init-capture
A C++14 feature allowing lambda parameters to capture and initialize members with arbitrary expressions.
lambda
An anonymous function object that can be defined inline.
Filed Under: c++language featurelambda