njames93 updated this revision to Diff 249307. njames93 added a comment. Herald added subscribers: arphaman, kbarton, nemanjai.
- Add usages, removed optional on arrayrefs Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D75714/new/ https://reviews.llvm.org/D75714 Files: clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp clang/include/clang/Basic/Diagnostic.h
Index: clang/include/clang/Basic/Diagnostic.h =================================================================== --- clang/include/clang/Basic/Diagnostic.h +++ clang/include/clang/Basic/Diagnostic.h @@ -21,6 +21,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" +#include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/iterator_range.h" @@ -1288,6 +1289,29 @@ return DB; } +inline const DiagnosticBuilder & +operator<<(const DiagnosticBuilder &DB, + const llvm::Optional<SourceRange> &Opt) { + if (Opt) + DB << *Opt; + return DB; +}; + +inline const DiagnosticBuilder & +operator<<(const DiagnosticBuilder &DB, + const llvm::Optional<CharSourceRange> &Opt) { + if (Opt) + DB << *Opt; + return DB; +}; + +inline const DiagnosticBuilder & +operator<<(const DiagnosticBuilder &DB, const llvm::Optional<FixItHint> &Opt) { + if (Opt) + DB << *Opt; + return DB; +}; + /// A nullability kind paired with a bit indicating whether it used a /// context-sensitive keyword. using DiagNullabilityKind = std::pair<NullabilityKind, bool>; Index: clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp +++ clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp @@ -429,11 +429,9 @@ if (MakeSmartPtrFunctionHeader.empty()) { return; } - if (auto IncludeFixit = Inserter->CreateIncludeInsertion( - FD, MakeSmartPtrFunctionHeader, - /*IsAngled=*/MakeSmartPtrFunctionHeader == StdMemoryHeader)) { - Diag << *IncludeFixit; - } + Diag << Inserter->CreateIncludeInsertion( + FD, MakeSmartPtrFunctionHeader, + /*IsAngled=*/MakeSmartPtrFunctionHeader == StdMemoryHeader); } } // namespace modernize Index: clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp +++ clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp @@ -86,13 +86,10 @@ SourceRange(BaseRange.getEnd().getLocWithOffset(1), IndexRange.getBegin().getLocWithOffset(-1)), ", ") - << FixItHint::CreateReplacement(Matched->getEndLoc(), ")"); - - Optional<FixItHint> Insertion = Inserter->CreateIncludeInsertion( - Result.SourceManager->getMainFileID(), GslHeader, - /*IsAngled=*/false); - if (Insertion) - Diag << Insertion.getValue(); + << FixItHint::CreateReplacement(Matched->getEndLoc(), ")") + << Inserter->CreateIncludeInsertion( + Result.SourceManager->getMainFileID(), GslHeader, + /*IsAngled=*/false); } return; } Index: clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp +++ clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp @@ -96,10 +96,8 @@ MatchedDecl->getName().size()), InitializationString); if (AddMathInclude) { - auto IncludeHint = IncludeInserter->CreateIncludeInsertion( + Diagnostic << IncludeInserter->CreateIncludeInsertion( Source.getFileID(MatchedDecl->getBeginLoc()), MathHeader, false); - if (IncludeHint) - Diagnostic << *IncludeHint; } } } Index: clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp +++ clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp @@ -105,12 +105,9 @@ // Create a preprocessor #include FixIt hint (CreateIncludeInsertion checks // whether this already exists). - auto IncludeHint = IncludeInserter->CreateIncludeInsertion( + Diagnostic << IncludeInserter->CreateIncludeInsertion( Source.getFileID(ComparisonExpr->getBeginLoc()), AbseilStringsMatchHeader, false); - if (IncludeHint) { - Diagnostic << *IncludeHint; - } } void StringFindStartswithCheck::registerPPCallbacks(
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits