================ @@ -359,24 +360,52 @@ void UseAfterMoveFinder::getReinits( } } +enum class MoveType { + Move, // std::move + Forward, // std::forward +}; + +static MoveType determineMoveType(const FunctionDecl *FuncDecl) { + if (FuncDecl->getName() == "move") + return MoveType::Move; + if (FuncDecl->getName() == "forward") + return MoveType::Forward; + + assert(false && "Invalid move type"); +} + static void emitDiagnostic(const Expr *MovingCall, const DeclRefExpr *MoveArg, const UseAfterMove &Use, ClangTidyCheck *Check, - ASTContext *Context) { + ASTContext *Context, MoveType Type) { SourceLocation UseLoc = Use.DeclRef->getExprLoc(); SourceLocation MoveLoc = MovingCall->getExprLoc(); - Check->diag(UseLoc, "'%0' used after it was moved") - << MoveArg->getDecl()->getName(); - Check->diag(MoveLoc, "move occurred here", DiagnosticIDs::Note); + StringRef ActionType; + StringRef ActionTypePastTense; + switch (Type) { + case MoveType::Move: + ActionType = "move"; + ActionTypePastTense = "moved"; + break; + case MoveType::Forward: + ActionType = "forward"; + ActionTypePastTense = "forwarded"; + break; + } + + Check->diag(UseLoc, "'%0' used after it was %1") + << MoveArg->getDecl()->getName() << ActionTypePastTense; + Check->diag(MoveLoc, "%0 occurred here", DiagnosticIDs::Note) << ActionType; if (Use.EvaluationOrderUndefined) { Check->diag(UseLoc, - "the use and move are unsequenced, i.e. there is no guarantee " + "the use and %0 are unsequenced, i.e. there is no guarantee " "about the order in which they are evaluated", - DiagnosticIDs::Note); + DiagnosticIDs::Note) + << ActionType; } else if (UseLoc < MoveLoc || Use.DeclRef == MoveArg) { - Check->diag(UseLoc, - "the use happens in a later loop iteration than the move", - DiagnosticIDs::Note); + Check->diag(UseLoc, "the use happens in a later loop iteration than the %0", + DiagnosticIDs::Note) + << ActionType; ---------------- 5chmidti wrote:
You could use the diagnostics 'select' syntax to do this in a more compact way: https://github.com/llvm/llvm-project/blob/be083dba95dfbbb0286d798cc06fbe021715bc03/clang-tools-extra/clang-tidy/hicpp/SignedBitwiseCheck.cpp#L96-L98 https://github.com/llvm/llvm-project/pull/82673 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits