I'm running cppcheck via an extension to VSCode (I have 3 or 4 C++ related extensions, and not sure part of which cppcheck is run), and noticed a false positive selfAssignment being flagged for cases where such assignment is required by compiler/spec.
cppcheck flags selfAssignment on the lambda definition capture list because it sees partB = partB.
However, at least in C++17 - I believe specification may've changed for C++20 - tuple decomposition doesn't create variables, but rather aliases (perhaps called something different in the spec), which can be used like variables in most, but not all scenarios. Capture list is one such place, and defining capture list as simply [partB](){...} results in the following error (clang):
Changing capture list to [partB = partB] creates a true partB variable (left side of assignment) from alias partB (right side of assignment), which can now be captured into lambda's closure.
CppCheck flagging selfAssignment due to seeing partB = partB is, therefore, a false positive.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm running cppcheck via an extension to VSCode (I have 3 or 4 C++ related extensions, and not sure part of which cppcheck is run), and noticed a false positive
selfAssignment
being flagged for cases where such assignment is required by compiler/spec.Consider the following code:
cppcheck flags
selfAssignment
on the lambda definition capture list because it seespartB = partB
.However, at least in C++17 - I believe specification may've changed for C++20 - tuple decomposition doesn't create variables, but rather aliases (perhaps called something different in the spec), which can be used like variables in most, but not all scenarios. Capture list is one such place, and defining capture list as simply
[partB](){...}
results in the following error (clang):Changing capture list to
[partB = partB]
creates a truepartB
variable (left side of assignment) from aliaspartB
(right side of assignment), which can now be captured into lambda's closure.CppCheck flagging
selfAssignment
due to seeingpartB = partB
is, therefore, a false positive.Thanks! I have created https://trac.cppcheck.net/ticket/10228