C++: Avoid TARGET_EXPR for constexpr class access in generic lambdas
Improves constexpr evaluation in templates by preventing unnecessary internal expression wrappers.
This change prevents the C++ compiler from using TARGET_EXPR to represent constexpr class values within template declarations. TARGET_EXPR is an internal implementation detail and not suitable for template code. By avoiding this wrapper when processing template declarations, the compiler ensures a cleaner representation of constant expressions, aligning with the goals of constexpr evaluation in templates.
In Details
During constant evaluation, C++ typically represents a constant class value using TARGET_EXPR. However, in the context of template declarations, TARGET_EXPR is considered an implementation detail and should not appear in the template's abstract representation. This commit modifies cxx_eval_outermost_constant_expr to skip wrapping the result in TARGET_EXPR when processing_template_decl is true, thus avoiding this internal detail from leaking into template instantiations.
- constexpr
- A C++ keyword that indicates a variable or function can be evaluated at compile time. This allows for performance optimizations and compile-time computations.
- TARGET_EXPR
- An internal GCC representation used to denote a target-specific expression, often employed during constant evaluation to represent complex expressions or class values. It is generally not meant to be exposed in high-level IRs or template instantiations.
- generic lambda
- A C++ lambda expression that uses
autofor its parameter types, allowing it to be a template. This enables more flexible and reusable lambda functions. - template declaration
- In C++, a declaration that defines a template, which is a blueprint for creating classes or functions. Template declarations are processed by the compiler to generate specific code based on template arguments.