Fix C++ constant evaluation in lambda scopes for PR126483.
C++ compiler now correctly handles constexpr evaluation within lambda scopes for PR126483.
This change corrects an issue where the C++ compiler prematurely folded initializers within lambda scopes, leading to incorrect is_constant_evaluated results. The fix involves using maybe_constexpr_fn instead of DECL_DECLARED_CONSTEXPR_P to determine if a lambda scope is constexpr-suitable, ensuring correct constant evaluation behavior.
In Details
In typeck2.cc, the store_init_value function's handling of copy-initialization within potentially constexpr lambdas was flawed. It relied on DECL_DECLARED_CONSTEXPR_P for the function scope, which was insufficient for lambdas whose constexpr status is determined later. This patch replaces that check with maybe_constexpr_fn, which correctly identifies constexpr-suitable lambdas, thus preventing premature folding and fixing PR126483.
- constexpr
- A C++ keyword that denotes that a variable or function's value can be determined at compile time. This enables compile-time evaluation, improving performance.
- constant evaluation
- The process by which the compiler determines the value of an expression at compile time rather than at runtime.
- lambda scope
- The region of code within a C++ lambda function where its variables and parameters are accessible.
- maybe_constexpr_fn
- A compiler internal function that checks if a function (including lambdas) *might* be evaluated at compile time, considering its body and context.