================
@@ -371,6 +392,21 @@ void
UnnecessaryCopyInitialization::diagnoseCopyFromLocalVar(
maybeIssueFixes(Ctx, Diagnostic);
}
+void UnnecessaryCopyInitialization::diagnoseCopyFromConstVarMember(
+ const CheckContext &Ctx, const VarDecl &OldVar, const MemberExpr &ME) {
+ std::string MEStr(Lexer::getSourceText(
+ CharSourceRange::getTokenRange(ME.getSourceRange()),
+ Ctx.ASTCtx.getSourceManager(), Ctx.ASTCtx.getLangOpts()));
+ auto Diagnostic =
+ diag(Ctx.Var.getLocation(),
+ "local copy %0 of the subobject '%1' of type %2 is never "
+ "modified%select{"
+ "| and never used}4; consider %select{avoiding the copy|removing "
+ "the statement}4")
+ << &Ctx.Var << MEStr << Ctx.Var.getType() << &OldVar << Ctx.IsVarUnused;
----------------
localspook wrote:
I think the check is correct to not warn in that case (and it would be good to
add a test to check that it doesn't). For the same reason that it doesn't warn
here:
https://github.com/llvm/llvm-project/blob/1c499351d682aa46c2f087a6f757d22b01d18aa7/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp#L852-L859
https://github.com/llvm/llvm-project/pull/151936
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits