[PATCH] D131780: [clang-tidy] Do not trigger cppcoreguidelines-avoid-const-or-ref-data-members on lambda captures

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 19 00:05:25 PDT 2022


njames93 accepted this revision.
njames93 added inline comments.
This revision is now accepted and ready to land.


================
Comment at: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp:191
+  auto r5 = [&x5]{};
+}
----------------
carlosgalvezp wrote:
> njames93 wrote:
> > njames93 wrote:
> > > Can you add some cases with implicit capture (using [=] and [&])
> > I should have been more clear, you need to actually use the variables inside the lambda to implicitly capture them.
> Thanks, didn't know that! 
> 
> It's actually quite interesting, implicit lambda captures never trigger an error:
> https://godbolt.org/z/cErf4jv8E
> 
> But it's probably good to keep the test anyway in case the lambda implementation changes.
> 
What's more interesting about that is the error message that was emitted.
```
<source>:6:16: warning: member '' of type 'const int' is const qualified [cppcoreguidelines-avoid-const-or-ref-data-members]
    auto y3 = [x]{};
```
However this fix should accidentally fix the issue of unnamed members.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131780/new/

https://reviews.llvm.org/D131780



More information about the cfe-commits mailing list