[clang] [Clang] correct error message when assigning to const reference captured in lambda (PR #105647)

Vlad Serebrennikov via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 22 11:31:05 PDT 2024


================
@@ -189,6 +189,11 @@ namespace ModifyingCapture {
     [=] {
       n = 1; // expected-error {{cannot assign to a variable captured by copy in a non-mutable lambda}}
     };
+    const int cn = 0;
+    // cxx03-cxx11-warning at +1 {{initialized lambda captures are a C++14 extension}}
+    [&cnr = cn]{ // expected-note {{variable 'cnr' declared const here}}
----------------
Endilll wrote:

Note emitted for this line is technically correct, because according to https://eel.is/c++draft/expr.prim.lambda#capture-6, this is where we deduce type of `cnr` to be `const int&`. But I believe it would be significantly more helpful if we point out to a `const` in the declaration of `cn`, because that's the real reason we can't perform the assignment.

https://github.com/llvm/llvm-project/pull/105647


More information about the cfe-commits mailing list