c++: capture of reference to global in template
Fixes a bug in C++ that caused a crash when capturing a reference to a global variable in a template lambda.
This commit fixes a bug that caused GCC to crash when a lambda expression inside a template captures a reference to a global variable. The issue arose because the compiler failed to properly evaluate the reference as a constant within the template context. The fix defers the error checking to instantiation time when the type dependencies are resolved, preventing the crash and ensuring correct code generation.
In Details
When a lambda captures a reference to a global variable inside a template, maybe_constant_value fails to evaluate the reference to (int&) &g, leaving it as c. The patch defers the error in process_outer_var_ref to instantiation time when the type is known. It also fixes a crash in mark_use relating to invalid lambda expressions.
For Context
In C++, lambda expressions are anonymous functions that can capture variables from their surrounding scope. When a lambda captures a variable, it creates a copy or a reference to that variable within the lambda's scope. Templates are blueprints for creating generic code that can work with different data types. This commit fixes a bug that occurred when a lambda inside a template captured a reference to a global variable, ensuring that the compiler handles this scenario correctly.