'this' capture in template
Fixed an issue where the 'const' qualifier was dropped from 'this' capture proxies in templates.
This commit fixes an issue in C++ lambda expressions where the ‘const’ qualifier was being dropped from the capture proxy when capturing ‘this’ in a template. This could lead to incorrect code generation when the captured ‘this’ pointer was expected to be const. The fix ensures that the capture proxy retains the ‘const’ qualifier, maintaining the correctness of ‘this’ capture in templates.
In Details
The fix modifies build_capture_proxy in lambda.cc to ensure that the 'this' capture proxy is const. The issue arose from a previous change (r16-1019) that inadvertently dropped the 'const' qualifier. This correction is specific to lambda capture handling and may primarily concern developers working on C++ lambda expressions and template instantiation.
For Context
In C++, a lambda expression is a short, anonymous function that can capture variables from its surrounding scope. When a lambda captures 'this', it captures a pointer to the current object. This commit fixes a bug that occurred when capturing 'this' inside a template function. The bug caused the compiler to lose the information that 'this' was a constant pointer, potentially leading to errors or unexpected behavior. The fix ensures that the compiler correctly captures 'this' as a constant pointer when needed.