Since its call operator is const but can modify the state of its underlying
functor we cannot tell whether the copy is necessary or not.
This avoids false positives.
Differential D89332
[clang-tidy] performance-unnecessary-copy-initialization: Always allow std::function to be copied. flx on Oct 13 2020, 10:39 AM. Authored by
Details Since its call operator is const but can modify the state of its underlying This avoids false positives.
Diff Detail
Event Timeline
Comment Actions How does this type alias and typedef, In theory that should also be handled. using Functor = std::function<...>; Functor Copy = Orig; // No warning.
Comment Actions Come to think of it, this is a pretty illogical way to solve this problem, just append ::std::function to the AllowedTypes vector in registerMatchers and be do with it. Will require dropping the const Qualifier on AllowedTypes, but aside from that it is a much simpler fix. Comment Actions This also seems like a reasonable alternative, to me.
Comment Actions Thank you all for the input! Good point. I added test cases that cover this and motivated the use of the hasName() matcher on the canonical type. AllowedTypes is currently matched using a regular expression on only the not fully qualified name of the NamedDecl: This is why this approach didn't work.
Comment Actions LGTM with an extra testing request (that should hopefully just work for you).
|
There's no need for this matcher -- hasName("::std::function") is the correct way to test for this.