From 7d6cea258429e300deeefac21ead530db75dae6b Mon Sep 17 00:00:00 2001 From: Alexander Kornienko Date: Wed, 25 Feb 2015 14:40:56 +0000 Subject: [PATCH] Add support for inserting ArrayRef into DiagnosticBuilder. This is going to be needed in clang-tidy as more checks add complex fixits. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@230495 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/Diagnostic.h | 11 +++++++++-- lib/Sema/SemaChecking.cpp | 10 ++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/include/clang/Basic/Diagnostic.h b/include/clang/Basic/Diagnostic.h index 6132ea34f6..f72809cab6 100644 --- a/include/clang/Basic/Diagnostic.h +++ b/include/clang/Basic/Diagnostic.h @@ -991,7 +991,8 @@ public: void AddFixItHint(const FixItHint &Hint) const { assert(isActive() && "Clients must not add to cleared diagnostic!"); - DiagObj->DiagFixItHints.push_back(Hint); + if (!Hint.isNull()) + DiagObj->DiagFixItHints.push_back(Hint); } void addFlagValue(StringRef V) const { DiagObj->FlagValue = V; } @@ -1095,7 +1096,13 @@ inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, const FixItHint &Hint) { - if (!Hint.isNull()) + DB.AddFixItHint(Hint); + return DB; +} + +inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB, + ArrayRef Hints) { + for (const FixItHint &Hint : Hints) DB.AddFixItHint(Hint); return DB; } diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index c26ba3cf9b..409a1b6ebd 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -3152,10 +3152,7 @@ void CheckFormatHandler::EmitFormatDiagnostic(Sema &S, bool InFunctionCall, if (InFunctionCall) { const Sema::SemaDiagnosticBuilder &D = S.Diag(Loc, PDiag); D << StringRange; - for (ArrayRef::iterator I = FixIt.begin(), E = FixIt.end(); - I != E; ++I) { - D << *I; - } + D << FixIt; } else { S.Diag(IsStringLocation ? ArgumentExpr->getExprLoc() : Loc, PDiag) << ArgumentExpr->getSourceRange(); @@ -3165,10 +3162,7 @@ void CheckFormatHandler::EmitFormatDiagnostic(Sema &S, bool InFunctionCall, diag::note_format_string_defined); Note << StringRange; - for (ArrayRef::iterator I = FixIt.begin(), E = FixIt.end(); - I != E; ++I) { - Note << *I; - } + Note << FixIt; } } -- 2.40.0