Extends the UnnecessaryCopyInitialization to detect copies of local variables and parameters that are unneeded.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
Please always add 'cfe-commits' to Subscribers when you send a patch for review (I've added it now).
Substantial comments later.
Thank you for the patch! Looks mostly good, a few style nits.
clang-tidy/performance/UnnecessaryCopyInitialization.cpp | ||
---|---|---|
21 ↗ | (On Diff #50602) | No need for clang::tidy:: here. |
43 ↗ | (On Diff #50602) | I guess, there's no need for ast_matchers:: here. |
127 ↗ | (On Diff #50602) | nit: I'd use a semicolon instead of the comma here, like in other clang-tidy messages. |
clang-tidy/performance/UnnecessaryCopyInitialization.h | ||
29 ↗ | (On Diff #50602) | LLVM style is to put *'s and &'s to the variable. Looks like your clang-format didn't understand it should use LLVM style. You might want to explicitly specify -style=llvm next time. |
clang-tidy/performance/UnnecessaryCopyInitialization.cpp | ||
---|---|---|
87 ↗ | (On Diff #50927) | I prefer to move the anonymous namespace under namespace performance { statement. |
test/clang-tidy/performance-unnecessary-copy-initialization.cpp | ||
232 ↗ | (On Diff #50927) | It would be nice to add a test case with copy_2 like: ExpensiveToCopyType orig; ExpensiveToCopyType copy_1 = orig; ExpensiveToCopyType copy_2 = copy_1; copy_1.constMethod(); copy_2.constMethod(); orig.constMethod(); |
LG
clang-tidy/performance/UnnecessaryCopyInitialization.cpp | ||
---|---|---|
21 ↗ | (On Diff #51215) | nit: Alternatively, you could return llvm::Optional<FixItHint> and apply it in the caller. Might result in a bit better separation of responsibilities. |
clang-tidy/performance/UnnecessaryCopyInitialization.cpp | ||
---|---|---|
21 ↗ | (On Diff #51289) | I am inclined to just leave it as is for the moment, this is already isolated code that doesn't escape the current file. |