C++: Improve handling of return value checks in expansion statements
Fixes an ICE and improves diagnostic handling for return value checks in C++ expansion statements.
This commit addresses an Internal Compiler Error (ICE) and improves diagnostic messages related to return value checks within C++ expansion statements. Previously, the compiler would ICE when attempting to instantiate expansion statements with dependent return values. The fix defers the full evaluation of check_return_expr until the final instantiation of the expansion statement, preventing the ICE. It also ensures that diagnostics accurately reflect the situation when return values are dependent or when specializations are involved.
In Details
In C++, expansion statements (e.g., within concepts or constraints) can involve dependent types. The check_return_expr function normally determines if a function returns a value. This change modifies its behavior within expansion statements (in_expansion_stmt). If a return value is dependent, check_return_expr now defers setting current_function_returns_value and related logic until later instantiation phases, preventing an ICE that occurred when trying to create dependent RESULT_DECLs prematurely. It also adjusts tsubst_stmt for partial specializations to similarly defer this che…
- expansion statement
- A type of statement in C++ template metaprogramming or concepts that expands based on template arguments or constraints.
- dependent type
- A type in C++ templates whose exact form cannot be determined until the template is instantiated with specific arguments.
- ICE
- Internal Compiler Error, a fatal error that occurs when the compiler encounters a situation it cannot handle, usually due to a bug.
- instantiation
- The process in C++ templates where the compiler generates a concrete version of a template based on the provided template arguments.
- RESULT_DECL
- An internal GCC representation for the declaration of a function's return value.