C++: Fix crash with TARGET_EXPR in assignment
C++ compiler no longer crashes when a lambda expression is used in an assignment, fixing PR127710.
This commit resolves a crash in the C++ compiler that occurred when a lambda expression, which generates a TARGET_EXPR, was used in an assignment. The issue stemmed from the TARGET_EXPR being incorrectly treated as a prvalue instead of an lvalue. The fix modifies the internal handling of TARGET_EXPRs to preserve their lvalue nature, ensuring correct behavior for copy-initialization scenarios.
In Details
The crash occurred in build_over_call due to a TARGET_EXPR being incorrectly reduced to a prvalue when it should have represented an lvalue bound to a temporary. The fix modifies force_lvalue to build a COMPOUND_EXPR with TARGET_EXPR_SLOT when dealing with TARGET_EXPR, preserving its lvalue nature and preventing the subsequent reduction. This addresses a subtle interaction between temporaries, assignment, and expression trees in the C++ frontend.
- TARGET_EXPR
- Represents a C++ prvalue that refers to a temporary object, often the result of a lambda or an unmaterialized expression.
- force_lvalue
- A GCC internal function that attempts to ensure an expression tree represents an lvalue, even if it's a prvalue.
- prvalue
- A 'pure rvalue' in C++, a temporary value that cannot be assigned to.
- COMPOUND_EXPR
- An expression that combines two subexpressions, where the first is evaluated for its side effects and the second is the value of the expression.