@@ -61,7 +61,7 @@ class ClangTidyDiagnosticRenderer : public DiagnosticRenderer {
6161 // FIXME: Remove this once there's a better way to pass check names than
6262 // appending the check name to the message in ClangTidyContext::diag and
6363 // using getCustomDiagID.
64- std::string CheckNameInMessage = " [" + Error.DiagnosticName + " ]" ;
64+ const std::string CheckNameInMessage = " [" + Error.DiagnosticName + " ]" ;
6565 Message.consume_back (CheckNameInMessage);
6666
6767 auto TidyMessage =
@@ -77,7 +77,7 @@ class ClangTidyDiagnosticRenderer : public DiagnosticRenderer {
7777 if (SourceRange.isCharRange ())
7878 return SourceRange;
7979 assert (SourceRange.isTokenRange ());
80- SourceLocation End = Lexer::getLocForEndOfToken (
80+ const SourceLocation End = Lexer::getLocForEndOfToken (
8181 SourceRange.getEnd (), 0 , Loc.getManager (), LangOpts);
8282 return CharSourceRange::getCharRange (SourceRange.getBegin (), End);
8383 };
@@ -114,14 +114,14 @@ class ClangTidyDiagnosticRenderer : public DiagnosticRenderer {
114114 Level == DiagnosticsEngine::Note ? &Error.Notes .back () : &Error.Message ;
115115
116116 for (const auto &FixIt : Hints) {
117- CharSourceRange Range = FixIt.RemoveRange ;
117+ const CharSourceRange Range = FixIt.RemoveRange ;
118118 assert (Range.getBegin ().isValid () && Range.getEnd ().isValid () &&
119119 " Invalid range in the fix-it hint." );
120120 assert (Range.getBegin ().isFileID () && Range.getEnd ().isFileID () &&
121121 " Only file locations supported in fix-it hints." );
122122
123- tooling::Replacement Replacement (Loc.getManager (), Range,
124- FixIt.CodeToInsert );
123+ const tooling::Replacement Replacement (Loc.getManager (), Range,
124+ FixIt.CodeToInsert );
125125 llvm::Error Err =
126126 DiagWithFix->Fix [Replacement.getFilePath ()].add (Replacement);
127127 // FIXME: better error handling (at least, don't let other replacements be
@@ -177,7 +177,7 @@ DiagnosticBuilder ClangTidyContext::diag(
177177 StringRef CheckName, SourceLocation Loc, StringRef Description,
178178 DiagnosticIDs::Level Level /* = DiagnosticIDs::Warning*/ ) {
179179 assert (Loc.isValid ());
180- unsigned ID = DiagEngine->getDiagnosticIDs ()->getCustomDiagID (
180+ const unsigned ID = DiagEngine->getDiagnosticIDs ()->getCustomDiagID (
181181 Level, (Description + " [" + CheckName + " ]" ).str ());
182182 CheckNamesByDiagnosticID.try_emplace (ID, CheckName);
183183 return DiagEngine->Report (Loc, ID);
@@ -186,7 +186,7 @@ DiagnosticBuilder ClangTidyContext::diag(
186186DiagnosticBuilder ClangTidyContext::diag (
187187 StringRef CheckName, StringRef Description,
188188 DiagnosticIDs::Level Level /* = DiagnosticIDs::Warning*/ ) {
189- unsigned ID = DiagEngine->getDiagnosticIDs ()->getCustomDiagID (
189+ const unsigned ID = DiagEngine->getDiagnosticIDs ()->getCustomDiagID (
190190 Level, (Description + " [" + CheckName + " ]" ).str ());
191191 CheckNamesByDiagnosticID.try_emplace (ID, CheckName);
192192 return DiagEngine->Report (ID);
@@ -195,10 +195,11 @@ DiagnosticBuilder ClangTidyContext::diag(
195195DiagnosticBuilder ClangTidyContext::diag (const tooling::Diagnostic &Error) {
196196 SourceManager &SM = DiagEngine->getSourceManager ();
197197 FileManager &FM = SM.getFileManager ();
198- FileEntryRef File = llvm::cantFail (FM.getFileRef (Error.Message .FilePath ));
199- FileID ID = SM.getOrCreateFileID (File, SrcMgr::C_User);
200- SourceLocation FileStartLoc = SM.getLocForStartOfFile (ID);
201- SourceLocation Loc = FileStartLoc.getLocWithOffset (
198+ const FileEntryRef File =
199+ llvm::cantFail (FM.getFileRef (Error.Message .FilePath ));
200+ const FileID ID = SM.getOrCreateFileID (File, SrcMgr::C_User);
201+ const SourceLocation FileStartLoc = SM.getLocForStartOfFile (ID);
202+ const SourceLocation Loc = FileStartLoc.getLocWithOffset (
202203 static_cast <SourceLocation::IntTy>(Error.Message .FileOffset ));
203204 return diag (Error.DiagnosticName , Loc, Error.Message .Message ,
204205 static_cast <DiagnosticIDs::Level>(Error.DiagLevel ));
@@ -214,7 +215,7 @@ bool ClangTidyContext::shouldSuppressDiagnostic(
214215 DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info,
215216 SmallVectorImpl<tooling::Diagnostic> &NoLintErrors, bool AllowIO,
216217 bool EnableNoLintBlocks) {
217- std::string CheckName = getCheckName (Info.getID ());
218+ const std::string CheckName = getCheckName (Info.getID ());
218219 return NoLintHandler.shouldSuppress (DiagLevel, Info, CheckName, NoLintErrors,
219220 AllowIO, EnableNoLintBlocks);
220221}
@@ -226,7 +227,7 @@ void ClangTidyContext::setSourceManager(SourceManager *SourceMgr) {
226227static bool parseFileExtensions (llvm::ArrayRef<std::string> AllFileExtensions,
227228 FileExtensionsSet &FileExtensions) {
228229 FileExtensions.clear ();
229- for (StringRef Suffix : AllFileExtensions) {
230+ for (const StringRef Suffix : AllFileExtensions) {
230231 StringRef Extension = Suffix.trim ();
231232 if (!llvm::all_of (Extension, isAlphanumeric))
232233 return false ;
@@ -294,11 +295,11 @@ bool ClangTidyContext::treatAsError(StringRef CheckName) const {
294295}
295296
296297std::string ClangTidyContext::getCheckName (unsigned DiagnosticID) const {
297- std::string ClangWarningOption = std::string (
298+ const std::string ClangWarningOption = std::string (
298299 DiagEngine->getDiagnosticIDs ()->getWarningOptionForDiag (DiagnosticID));
299300 if (!ClangWarningOption.empty ())
300301 return " clang-diagnostic-" + ClangWarningOption;
301- llvm::DenseMap<unsigned , std::string>::const_iterator I =
302+ const llvm::DenseMap<unsigned , std::string>::const_iterator I =
302303 CheckNamesByDiagnosticID.find (DiagnosticID);
303304 if (I != CheckNamesByDiagnosticID.end ())
304305 return I->second ;
@@ -316,7 +317,7 @@ ClangTidyDiagnosticConsumer::ClangTidyDiagnosticConsumer(
316317
317318void ClangTidyDiagnosticConsumer::finalizeLastError () {
318319 if (!Errors.empty ()) {
319- ClangTidyError &Error = Errors.back ();
320+ const ClangTidyError &Error = Errors.back ();
320321 if (Error.DiagnosticName == " clang-tidy-config" ) {
321322 // Never ignore these.
322323 } else if (!Context.isCheckEnabled (Error.DiagnosticName ) &&
@@ -436,8 +437,8 @@ void ClangTidyDiagnosticConsumer::HandleDiagnostic(
436437 Level = ClangTidyError::Remark;
437438 }
438439
439- bool IsWarningAsError = DiagLevel == DiagnosticsEngine::Warning &&
440- Context.treatAsError (CheckName);
440+ const bool IsWarningAsError = DiagLevel == DiagnosticsEngine::Warning &&
441+ Context.treatAsError (CheckName);
441442 Errors.emplace_back (CheckName, Level, Context.getCurrentBuildDirectory (),
442443 IsWarningAsError);
443444 }
@@ -491,8 +492,9 @@ void ClangTidyDiagnosticConsumer::forwardDiagnostic(const Diagnostic &Info) {
491492 // Acquire a diagnostic ID also in the external diagnostics engine.
492493 auto DiagLevelAndFormatString =
493494 Context.getDiagLevelAndFormatString (Info.getID (), Info.getLocation ());
494- unsigned ExternalID = ExternalDiagEngine->getDiagnosticIDs ()->getCustomDiagID (
495- DiagLevelAndFormatString.first , DiagLevelAndFormatString.second );
495+ const unsigned ExternalID =
496+ ExternalDiagEngine->getDiagnosticIDs ()->getCustomDiagID (
497+ DiagLevelAndFormatString.first , DiagLevelAndFormatString.second );
496498
497499 // Forward the details.
498500 auto Builder = ExternalDiagEngine->Report (Info.getLocation (), ExternalID);
@@ -501,7 +503,7 @@ void ClangTidyDiagnosticConsumer::forwardDiagnostic(const Diagnostic &Info) {
501503 for (auto Range : Info.getRanges ())
502504 Builder << Range;
503505 for (unsigned Index = 0 ; Index < Info.getNumArgs (); ++Index) {
504- DiagnosticsEngine::ArgumentKind Kind = Info.getArgKind (Index);
506+ const DiagnosticsEngine::ArgumentKind Kind = Info.getArgKind (Index);
505507 switch (Kind) {
506508 case clang::DiagnosticsEngine::ak_std_string:
507509 Builder << Info.getArgStdStr (Index);
@@ -574,7 +576,7 @@ void ClangTidyDiagnosticConsumer::checkFilters(SourceLocation Location,
574576 // FIXME: We start with a conservative approach here, but the actual type of
575577 // location needed depends on the check (in particular, where this check wants
576578 // to apply fixes).
577- FileID FID = Sources.getDecomposedExpansionLoc (Location).first ;
579+ const FileID FID = Sources.getDecomposedExpansionLoc (Location).first ;
578580 OptionalFileEntryRef File = Sources.getFileEntryRefForID (FID);
579581
580582 // -DMACRO definitions on the command line have locations in a virtual buffer
@@ -585,13 +587,13 @@ void ClangTidyDiagnosticConsumer::checkFilters(SourceLocation Location,
585587 return ;
586588 }
587589
588- StringRef FileName (File->getName ());
590+ const StringRef FileName (File->getName ());
589591 LastErrorRelatesToUserCode = LastErrorRelatesToUserCode ||
590592 Sources.isInMainFile (Location) ||
591593 (getHeaderFilter ()->match (FileName) &&
592594 !getExcludeHeaderFilter ()->match (FileName));
593595
594- unsigned LineNumber = Sources.getExpansionLineNumber (Location);
596+ const unsigned LineNumber = Sources.getExpansionLineNumber (Location);
595597 LastErrorPassesLineFilter =
596598 LastErrorPassesLineFilter || passesLineFilter (FileName, LineNumber);
597599}
@@ -707,8 +709,8 @@ void ClangTidyDiagnosticConsumer::removeIncompatibleErrors() {
707709 for (unsigned I = 0 ; I < ErrorFixes.size (); ++I) {
708710 for (const auto &FileAndReplace : *ErrorFixes[I].second ) {
709711 for (const auto &Replace : FileAndReplace.second ) {
710- unsigned Begin = Replace.getOffset ();
711- unsigned End = Begin + Replace.getLength ();
712+ const unsigned Begin = Replace.getOffset ();
713+ const unsigned End = Begin + Replace.getLength ();
712714 auto &Events = FileEvents[Replace.getFilePath ()];
713715 if (Begin == End) {
714716 Events.emplace_back (Begin, End, Event::ET_Insert, I, Sizes[I]);
@@ -767,7 +769,7 @@ struct LessClangTidyError {
767769};
768770struct EqualClangTidyError {
769771 bool operator ()(const ClangTidyError &LHS, const ClangTidyError &RHS) const {
770- LessClangTidyError Less;
772+ const LessClangTidyError Less;
771773 return !Less (LHS, RHS) && !Less (RHS, LHS);
772774 }
773775};
@@ -803,7 +805,7 @@ void ClangTidyDiagnosticConsumer::removeDuplicatedDiagnosticsOfAliasCheckers() {
803805 auto IT = Errors.begin ();
804806 while (IT != Errors.end ()) {
805807 ClangTidyError &Error = *IT;
806- std::pair<UniqueErrorSet::iterator, bool > Inserted =
808+ const std::pair<UniqueErrorSet::iterator, bool > Inserted =
807809 UniqueErrors.insert (&Error);
808810
809811 // Unique error, we keep it and move along.
0 commit comments