Lambdas are implemented as regular classes internally,
and the captured variables end up as members there.
Do not diagnose those - the check should cover only
regular classes and structs.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Thanks for the quick review, @Eugene.Zelenko !
This check was newly added a couple of days ago (as per the "New checks" section in the Release Notes). I thought the "Changes to exiting checks" section was only meant for checks already existing prior to the new release, to avoid adding excessive clutter to the documentation. New checks typically take a few iterations to polish when testing on larger projects.
What do you think?
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp | ||
---|---|---|
191 | Can you add some cases with implicit capture (using [=] and [&]) |
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp | ||
---|---|---|
191 | I should have been more clear, you need to actually use the variables inside the lambda to implicitly capture them. |
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp | ||
---|---|---|
191 | Thanks, didn't know that! It's actually quite interesting, implicit lambda captures never trigger an error: But it's probably good to keep the test anyway in case the lambda implementation changes. |
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/avoid-const-or-ref-data-members.cpp | ||
---|---|---|
191 | 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. |
Can you add some cases with implicit capture (using [=] and [&])