================ @@ -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; ---------------- movie-travel-code wrote:
I have added the test about the template cases. Do not issue warning when `OldVar` and `NewVar` come from different template types respectively. If only `OldVar` is from the template type and `NewVar` is `auto` , then issue a warning on demand. https://github.com/llvm/llvm-project/pull/151936 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits