Extends the UnnecessaryCopyInitialization to detect copies of local variables and parameters that are unneeded.
Details
Diff Detail
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 | ||
---|---|---|
36 | No need for clang::tidy:: here. | |
58 | I guess, there's no need for ast_matchers:: here. | |
128 | nit: I'd use a semicolon instead of the comma here, like in other clang-tidy messages. | |
clang-tidy/performance/UnnecessaryCopyInitialization.h | ||
29 | 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 | ||
---|---|---|
102 | I prefer to move the anonymous namespace under namespace performance { statement. | |
test/clang-tidy/performance-unnecessary-copy-initialization.cpp | ||
232 | 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 | 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 | I am inclined to just leave it as is for the moment, this is already isolated code that doesn't escape the current file. |
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.