[clang-tools-extra] [clang-tidy] performance-unnecessary-copy-init: Add a hook... (PR #73921)

Clement Courbet via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 6 09:28:03 PST 2023


================
@@ -261,21 +262,27 @@ void UnnecessaryCopyInitialization::registerMatchers(MatchFinder *Finder) {
                      this);
 }
 
+UnnecessaryCopyInitialization::CheckContext::CheckContext(
----------------
legrosbuffle wrote:

I think it's a simple matter of preference, I think we can see the constructor as a factory function for the context.

To me the following are all kind of equivalent:
  - `CheckContext Context(Result);`
  - `CheckContext Context = MakeContext(Result);`
  - `CheckContext Context{NewVar, ...}`

With the caveat that the latter allows putting the context in an invalid state (e.g. with `IsVarUnused` in an inconsistent value w.r.t. `Var`). Anyway I don't feel strongly, so I've switched to a raw struct without ctor as suggested. 


https://github.com/llvm/llvm-project/pull/73921


More information about the cfe-commits mailing list