On Wed, Feb 25, 2015 at 6:39 PM, David Blaikie <[email protected]> wrote:
> > > On Wed, Feb 25, 2015 at 6:40 AM, Alexander Kornienko <[email protected]> > wrote: > >> Author: alexfh >> Date: Wed Feb 25 08:40:56 2015 >> New Revision: 230495 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=230495&view=rev >> Log: >> Add support for inserting ArrayRef<FixItHint> into DiagnosticBuilder. >> >> This is going to be needed in clang-tidy as more checks add complex >> fixits. >> >> Modified: >> cfe/trunk/include/clang/Basic/Diagnostic.h >> cfe/trunk/lib/Sema/SemaChecking.cpp >> >> Modified: cfe/trunk/include/clang/Basic/Diagnostic.h >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=230495&r1=230494&r2=230495&view=diff >> >> ============================================================================== >> --- cfe/trunk/include/clang/Basic/Diagnostic.h (original) >> +++ cfe/trunk/include/clang/Basic/Diagnostic.h Wed Feb 25 08:40:56 2015 >> @@ -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()) >> > > Why is this null check required/used? (it'd be nicer to hold the invariant > that the FixItHints can't be null, if possible/reasonable) > The check for isNull() in the operator<< was added in r153122 <http://reviews.llvm.org/rL153122> "Don't include FixIts with a null replacement range. Fixes rdar://problem/11040133". > > (also, if we do need FixItHints to have a null state, perhaps they should > be boolean testable with an explicit operator bool) > The FixItHint::isNull() method is used just a handful of times in the code. I don't know whether it makes sense to introduce a conversion to boolean to make these usages simpler. > > >> + DiagObj->DiagFixItHints.push_back(Hint); >> } >> >> void addFlagValue(StringRef V) const { DiagObj->FlagValue = V; } >> @@ -1095,7 +1096,13 @@ inline const DiagnosticBuilder &operator >> >> 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<FixItHint> Hints) { >> + for (const FixItHint &Hint : Hints) >> DB.AddFixItHint(Hint); >> return DB; >> } >> >> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=230495&r1=230494&r2=230495&view=diff >> >> ============================================================================== >> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original) >> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Feb 25 08:40:56 2015 >> @@ -3152,10 +3152,7 @@ void CheckFormatHandler::EmitFormatDiagn >> if (InFunctionCall) { >> const Sema::SemaDiagnosticBuilder &D = S.Diag(Loc, PDiag); >> D << StringRange; >> - for (ArrayRef<FixItHint>::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::EmitFormatDiagn >> diag::note_format_string_defined); >> >> Note << StringRange; >> - for (ArrayRef<FixItHint>::iterator I = FixIt.begin(), E = >> FixIt.end(); >> - I != E; ++I) { >> - Note << *I; >> - } >> + Note << FixIt; >> } >> } >> >> >> >> _______________________________________________ >> cfe-commits mailing list >> [email protected] >> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits >> >
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
