c++: improve lambda capture of typeid expressions
Fixes a bug where generic lambdas incorrectly skipped capturing local entities in typeid expressions.
A bug in C++ lambda capture has been fixed, resolving an ICE that occurred when generic lambdas interacted with typeid expressions. Previously, the compiler could incorrectly skip capturing local entities required by the C++ standard when evaluating typeid. This change modifies how the compiler determines if a typeid expression necessitates a capture, ensuring correct behavior even within template contexts and for complex nested typeid expressions. A new mechanism, cp_unevaluated_typeid_cutoff, is introduced to manage this evaluation process.
In Details
The change in expr.prim.lambda.capture (P0588R1 / CWG1468) corrects the interaction between generic lambdas and typeid. Previously, processing_template_decl == 0 incorrectly gated the re-parse required for capture analysis. This commit introduces cp_unevaluated_typeid_cutoff to properly manage capture suppression when typeid operands are unevaluated, particularly in nested typeid expressions or within template declarations. mark_used and resolves_to_fixed_type_p are adjusted to respect template contexts without suppressing necessary instantiation checks.
- generic lambda
- A C++ lambda expression that uses
autofor its parameter types, allowing it to deduce types at compile time, similar to a function template. - typeid
- A C++ operator that returns a
std::type_infoobject representing the type of an expression. It can trigger runtime type information lookups. - ICE
- Internal Compiler Error. A fatal error during compilation that indicates a bug within the compiler itself.
- template declaration
- A C++ construct that defines a blueprint for creating classes or functions, allowing them to operate on different types without rewriting the entire code.