-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[clang-tidy][NFC] Fix misc-const-correctness warnings (1/N) #167030
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,7 +61,7 @@ class ClangTidyDiagnosticRenderer : public DiagnosticRenderer { | |
| // FIXME: Remove this once there's a better way to pass check names than | ||
| // appending the check name to the message in ClangTidyContext::diag and | ||
| // using getCustomDiagID. | ||
| std::string CheckNameInMessage = " [" + Error.DiagnosticName + "]"; | ||
| const std::string CheckNameInMessage = " [" + Error.DiagnosticName + "]"; | ||
| Message.consume_back(CheckNameInMessage); | ||
|
|
||
| auto TidyMessage = | ||
|
|
@@ -77,7 +77,7 @@ class ClangTidyDiagnosticRenderer : public DiagnosticRenderer { | |
| if (SourceRange.isCharRange()) | ||
| return SourceRange; | ||
| assert(SourceRange.isTokenRange()); | ||
| SourceLocation End = Lexer::getLocForEndOfToken( | ||
| const SourceLocation End = Lexer::getLocForEndOfToken( | ||
| SourceRange.getEnd(), 0, Loc.getManager(), LangOpts); | ||
| return CharSourceRange::getCharRange(SourceRange.getBegin(), End); | ||
| }; | ||
|
|
@@ -114,14 +114,14 @@ class ClangTidyDiagnosticRenderer : public DiagnosticRenderer { | |
| Level == DiagnosticsEngine::Note ? &Error.Notes.back() : &Error.Message; | ||
|
|
||
| for (const auto &FixIt : Hints) { | ||
| CharSourceRange Range = FixIt.RemoveRange; | ||
| const CharSourceRange Range = FixIt.RemoveRange; | ||
| assert(Range.getBegin().isValid() && Range.getEnd().isValid() && | ||
| "Invalid range in the fix-it hint."); | ||
| assert(Range.getBegin().isFileID() && Range.getEnd().isFileID() && | ||
| "Only file locations supported in fix-it hints."); | ||
|
|
||
| tooling::Replacement Replacement(Loc.getManager(), Range, | ||
| FixIt.CodeToInsert); | ||
| const tooling::Replacement Replacement(Loc.getManager(), Range, | ||
| FixIt.CodeToInsert); | ||
| llvm::Error Err = | ||
| DiagWithFix->Fix[Replacement.getFilePath()].add(Replacement); | ||
| // FIXME: better error handling (at least, don't let other replacements be | ||
|
|
@@ -177,7 +177,7 @@ DiagnosticBuilder ClangTidyContext::diag( | |
| StringRef CheckName, SourceLocation Loc, StringRef Description, | ||
| DiagnosticIDs::Level Level /* = DiagnosticIDs::Warning*/) { | ||
| assert(Loc.isValid()); | ||
| unsigned ID = DiagEngine->getDiagnosticIDs()->getCustomDiagID( | ||
| const unsigned ID = DiagEngine->getDiagnosticIDs()->getCustomDiagID( | ||
| Level, (Description + " [" + CheckName + "]").str()); | ||
| CheckNamesByDiagnosticID.try_emplace(ID, CheckName); | ||
| return DiagEngine->Report(Loc, ID); | ||
|
|
@@ -186,7 +186,7 @@ DiagnosticBuilder ClangTidyContext::diag( | |
| DiagnosticBuilder ClangTidyContext::diag( | ||
| StringRef CheckName, StringRef Description, | ||
| DiagnosticIDs::Level Level /* = DiagnosticIDs::Warning*/) { | ||
| unsigned ID = DiagEngine->getDiagnosticIDs()->getCustomDiagID( | ||
| const unsigned ID = DiagEngine->getDiagnosticIDs()->getCustomDiagID( | ||
| Level, (Description + " [" + CheckName + "]").str()); | ||
| CheckNamesByDiagnosticID.try_emplace(ID, CheckName); | ||
| return DiagEngine->Report(ID); | ||
|
|
@@ -195,10 +195,11 @@ DiagnosticBuilder ClangTidyContext::diag( | |
| DiagnosticBuilder ClangTidyContext::diag(const tooling::Diagnostic &Error) { | ||
| SourceManager &SM = DiagEngine->getSourceManager(); | ||
| FileManager &FM = SM.getFileManager(); | ||
| FileEntryRef File = llvm::cantFail(FM.getFileRef(Error.Message.FilePath)); | ||
| FileID ID = SM.getOrCreateFileID(File, SrcMgr::C_User); | ||
| SourceLocation FileStartLoc = SM.getLocForStartOfFile(ID); | ||
| SourceLocation Loc = FileStartLoc.getLocWithOffset( | ||
| const FileEntryRef File = | ||
| llvm::cantFail(FM.getFileRef(Error.Message.FilePath)); | ||
| const FileID ID = SM.getOrCreateFileID(File, SrcMgr::C_User); | ||
| const SourceLocation FileStartLoc = SM.getLocForStartOfFile(ID); | ||
| const SourceLocation Loc = FileStartLoc.getLocWithOffset( | ||
| static_cast<SourceLocation::IntTy>(Error.Message.FileOffset)); | ||
| return diag(Error.DiagnosticName, Loc, Error.Message.Message, | ||
| static_cast<DiagnosticIDs::Level>(Error.DiagLevel)); | ||
|
|
@@ -214,7 +215,7 @@ bool ClangTidyContext::shouldSuppressDiagnostic( | |
| DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info, | ||
| SmallVectorImpl<tooling::Diagnostic> &NoLintErrors, bool AllowIO, | ||
| bool EnableNoLintBlocks) { | ||
| std::string CheckName = getCheckName(Info.getID()); | ||
| const std::string CheckName = getCheckName(Info.getID()); | ||
| return NoLintHandler.shouldSuppress(DiagLevel, Info, CheckName, NoLintErrors, | ||
| AllowIO, EnableNoLintBlocks); | ||
| } | ||
|
|
@@ -226,7 +227,7 @@ void ClangTidyContext::setSourceManager(SourceManager *SourceMgr) { | |
| static bool parseFileExtensions(llvm::ArrayRef<std::string> AllFileExtensions, | ||
| FileExtensionsSet &FileExtensions) { | ||
| FileExtensions.clear(); | ||
| for (StringRef Suffix : AllFileExtensions) { | ||
| for (const StringRef Suffix : AllFileExtensions) { | ||
| StringRef Extension = Suffix.trim(); | ||
| if (!llvm::all_of(Extension, isAlphanumeric)) | ||
| return false; | ||
|
|
@@ -294,11 +295,11 @@ bool ClangTidyContext::treatAsError(StringRef CheckName) const { | |
| } | ||
|
|
||
| std::string ClangTidyContext::getCheckName(unsigned DiagnosticID) const { | ||
| std::string ClangWarningOption = std::string( | ||
| const std::string ClangWarningOption = std::string( | ||
| DiagEngine->getDiagnosticIDs()->getWarningOptionForDiag(DiagnosticID)); | ||
| if (!ClangWarningOption.empty()) | ||
| return "clang-diagnostic-" + ClangWarningOption; | ||
| llvm::DenseMap<unsigned, std::string>::const_iterator I = | ||
| const llvm::DenseMap<unsigned, std::string>::const_iterator I = | ||
| CheckNamesByDiagnosticID.find(DiagnosticID); | ||
| if (I != CheckNamesByDiagnosticID.end()) | ||
| return I->second; | ||
|
|
@@ -316,7 +317,7 @@ ClangTidyDiagnosticConsumer::ClangTidyDiagnosticConsumer( | |
|
|
||
| void ClangTidyDiagnosticConsumer::finalizeLastError() { | ||
| if (!Errors.empty()) { | ||
| ClangTidyError &Error = Errors.back(); | ||
| const ClangTidyError &Error = Errors.back(); | ||
| if (Error.DiagnosticName == "clang-tidy-config") { | ||
| // Never ignore these. | ||
| } else if (!Context.isCheckEnabled(Error.DiagnosticName) && | ||
|
|
@@ -436,8 +437,8 @@ void ClangTidyDiagnosticConsumer::HandleDiagnostic( | |
| Level = ClangTidyError::Remark; | ||
| } | ||
|
|
||
| bool IsWarningAsError = DiagLevel == DiagnosticsEngine::Warning && | ||
| Context.treatAsError(CheckName); | ||
| const bool IsWarningAsError = DiagLevel == DiagnosticsEngine::Warning && | ||
| Context.treatAsError(CheckName); | ||
| Errors.emplace_back(CheckName, Level, Context.getCurrentBuildDirectory(), | ||
| IsWarningAsError); | ||
| } | ||
|
|
@@ -491,8 +492,9 @@ void ClangTidyDiagnosticConsumer::forwardDiagnostic(const Diagnostic &Info) { | |
| // Acquire a diagnostic ID also in the external diagnostics engine. | ||
| auto DiagLevelAndFormatString = | ||
| Context.getDiagLevelAndFormatString(Info.getID(), Info.getLocation()); | ||
| unsigned ExternalID = ExternalDiagEngine->getDiagnosticIDs()->getCustomDiagID( | ||
| DiagLevelAndFormatString.first, DiagLevelAndFormatString.second); | ||
| const unsigned ExternalID = | ||
| ExternalDiagEngine->getDiagnosticIDs()->getCustomDiagID( | ||
| DiagLevelAndFormatString.first, DiagLevelAndFormatString.second); | ||
|
|
||
| // Forward the details. | ||
| auto Builder = ExternalDiagEngine->Report(Info.getLocation(), ExternalID); | ||
|
|
@@ -501,7 +503,7 @@ void ClangTidyDiagnosticConsumer::forwardDiagnostic(const Diagnostic &Info) { | |
| for (auto Range : Info.getRanges()) | ||
| Builder << Range; | ||
| for (unsigned Index = 0; Index < Info.getNumArgs(); ++Index) { | ||
| DiagnosticsEngine::ArgumentKind Kind = Info.getArgKind(Index); | ||
| const DiagnosticsEngine::ArgumentKind Kind = Info.getArgKind(Index); | ||
| switch (Kind) { | ||
| case clang::DiagnosticsEngine::ak_std_string: | ||
| Builder << Info.getArgStdStr(Index); | ||
|
|
@@ -574,7 +576,7 @@ void ClangTidyDiagnosticConsumer::checkFilters(SourceLocation Location, | |
| // FIXME: We start with a conservative approach here, but the actual type of | ||
| // location needed depends on the check (in particular, where this check wants | ||
| // to apply fixes). | ||
| FileID FID = Sources.getDecomposedExpansionLoc(Location).first; | ||
| const FileID FID = Sources.getDecomposedExpansionLoc(Location).first; | ||
| OptionalFileEntryRef File = Sources.getFileEntryRefForID(FID); | ||
|
|
||
| // -DMACRO definitions on the command line have locations in a virtual buffer | ||
|
|
@@ -585,13 +587,13 @@ void ClangTidyDiagnosticConsumer::checkFilters(SourceLocation Location, | |
| return; | ||
| } | ||
|
|
||
| StringRef FileName(File->getName()); | ||
| const StringRef FileName(File->getName()); | ||
| LastErrorRelatesToUserCode = LastErrorRelatesToUserCode || | ||
| Sources.isInMainFile(Location) || | ||
| (getHeaderFilter()->match(FileName) && | ||
| !getExcludeHeaderFilter()->match(FileName)); | ||
|
|
||
| unsigned LineNumber = Sources.getExpansionLineNumber(Location); | ||
| const unsigned LineNumber = Sources.getExpansionLineNumber(Location); | ||
| LastErrorPassesLineFilter = | ||
| LastErrorPassesLineFilter || passesLineFilter(FileName, LineNumber); | ||
| } | ||
|
|
@@ -707,8 +709,8 @@ void ClangTidyDiagnosticConsumer::removeIncompatibleErrors() { | |
| for (unsigned I = 0; I < ErrorFixes.size(); ++I) { | ||
| for (const auto &FileAndReplace : *ErrorFixes[I].second) { | ||
| for (const auto &Replace : FileAndReplace.second) { | ||
| unsigned Begin = Replace.getOffset(); | ||
| unsigned End = Begin + Replace.getLength(); | ||
| const unsigned Begin = Replace.getOffset(); | ||
| const unsigned End = Begin + Replace.getLength(); | ||
| auto &Events = FileEvents[Replace.getFilePath()]; | ||
| if (Begin == End) { | ||
| Events.emplace_back(Begin, End, Event::ET_Insert, I, Sizes[I]); | ||
|
|
@@ -767,7 +769,7 @@ struct LessClangTidyError { | |
| }; | ||
| struct EqualClangTidyError { | ||
| bool operator()(const ClangTidyError &LHS, const ClangTidyError &RHS) const { | ||
| LessClangTidyError Less; | ||
| const LessClangTidyError Less; | ||
| return !Less(LHS, RHS) && !Less(RHS, LHS); | ||
| } | ||
| }; | ||
|
|
@@ -803,7 +805,7 @@ void ClangTidyDiagnosticConsumer::removeDuplicatedDiagnosticsOfAliasCheckers() { | |
| auto IT = Errors.begin(); | ||
| while (IT != Errors.end()) { | ||
| ClangTidyError &Error = *IT; | ||
| std::pair<UniqueErrorSet::iterator, bool> Inserted = | ||
| const std::pair<UniqueErrorSet::iterator, bool> Inserted = | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Structural binding? But this could be left for dedicated pull request.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't have the check in I don't see much value now in fixing one by one by hand. |
||
| UniqueErrors.insert(&Error); | ||
|
|
||
| // Unique error, we keep it and move along. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.