{{>Comments}}
diff --git a/clang-tools-extra/clang-doc/assets/namespace-template.mustache b/clang-tools-extra/clang-doc/assets/namespace-template.mustache
index d96bc5ce91f3a..f4a35cfe4c79a 100644
--- a/clang-tools-extra/clang-doc/assets/namespace-template.mustache
+++ b/clang-tools-extra/clang-doc/assets/namespace-template.mustache
@@ -92,9 +92,7 @@
{{#Records}}
-
- class {{Name}}
-
+ class {{Name}}
{{/Records}}
diff --git a/clang-tools-extra/clang-tidy/.clang-tidy b/clang-tools-extra/clang-tidy/.clang-tidy
index 0c2f34b529016..2cd9af494c1ec 100644
--- a/clang-tools-extra/clang-tidy/.clang-tidy
+++ b/clang-tools-extra/clang-tidy/.clang-tidy
@@ -15,7 +15,6 @@ Checks: >
performance-*,
-performance-enum-size,
-performance-no-int-to-ptr,
- -performance-unnecessary-value-param,
readability-*,
-readability-avoid-nested-conditional-operator,
-readability-braces-around-statements,
diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp
index 7e18f3806a143..7b40c80653ebc 100644
--- a/clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -117,7 +117,8 @@ class ErrorReporter {
void reportDiagnostic(const ClangTidyError &Error) {
const tooling::DiagnosticMessage &Message = Error.Message;
- SourceLocation Loc = getLocation(Message.FilePath, Message.FileOffset);
+ const SourceLocation Loc =
+ getLocation(Message.FilePath, Message.FileOffset);
// Contains a pair for each attempted fix: location and whether the fix was
// applied successfully.
SmallVector
, 4> FixLocations;
@@ -157,11 +158,11 @@ class ErrorReporter {
// FIXME: Implement better conflict handling.
llvm::errs() << "Trying to resolve conflict: "
<< llvm::toString(std::move(Err)) << "\n";
- unsigned NewOffset =
+ const unsigned NewOffset =
Replacements.getShiftedCodePosition(R.getOffset());
- unsigned NewLength = Replacements.getShiftedCodePosition(
- R.getOffset() + R.getLength()) -
- NewOffset;
+ const unsigned NewLength = Replacements.getShiftedCodePosition(
+ R.getOffset() + R.getLength()) -
+ NewOffset;
if (NewLength == R.getLength()) {
R = Replacement(R.getFilePath(), NewOffset, NewLength,
R.getReplacementText());
@@ -200,7 +201,7 @@ class ErrorReporter {
for (const auto &FileAndReplacements : FileReplacements) {
Rewriter Rewrite(SourceMgr, LangOpts);
- StringRef File = FileAndReplacements.first();
+ const StringRef File = FileAndReplacements.first();
VFS.setCurrentWorkingDirectory(FileAndReplacements.second.BuildDir);
llvm::ErrorOr> Buffer =
SourceMgr.getFileManager().getBufferForFile(File);
@@ -210,7 +211,7 @@ class ErrorReporter {
// FIXME: Maybe don't apply fixes for other files as well.
continue;
}
- StringRef Code = Buffer.get()->getBuffer();
+ const StringRef Code = Buffer.get()->getBuffer();
auto Style = format::getStyle(
*Context.getOptionsForFile(File).FormatStyle, File, "none");
if (!Style) {
@@ -262,7 +263,7 @@ class ErrorReporter {
if (!File)
return {};
- FileID ID = SourceMgr.getOrCreateFileID(*File, SrcMgr::C_User);
+ const FileID ID = SourceMgr.getOrCreateFileID(*File, SrcMgr::C_User);
return SourceMgr.getLocForStartOfFile(ID).getLocWithOffset(Offset);
}
@@ -284,7 +285,8 @@ class ErrorReporter {
}
void reportNote(const tooling::DiagnosticMessage &Message) {
- SourceLocation Loc = getLocation(Message.FilePath, Message.FileOffset);
+ const SourceLocation Loc =
+ getLocation(Message.FilePath, Message.FileOffset);
auto Diag =
Diags.Report(Loc, Diags.getCustomDiagID(DiagnosticsEngine::Note, "%0"))
<< Message.Message;
@@ -296,8 +298,9 @@ class ErrorReporter {
CharSourceRange getRange(const FileByteRange &Range) {
SmallString<128> AbsoluteFilePath{Range.FilePath};
Files.makeAbsolutePath(AbsoluteFilePath);
- SourceLocation BeginLoc = getLocation(AbsoluteFilePath, Range.FileOffset);
- SourceLocation EndLoc = BeginLoc.getLocWithOffset(Range.Length);
+ const SourceLocation BeginLoc =
+ getLocation(AbsoluteFilePath, Range.FileOffset);
+ const SourceLocation EndLoc = BeginLoc.getLocWithOffset(Range.Length);
// Retrieve the source range for applicable highlights and fixes. Macro
// definition on the command line have locations in a virtual buffer and
// don't have valid file paths and are therefore not applicable.
@@ -353,7 +356,8 @@ ClangTidyASTConsumerFactory::ClangTidyASTConsumerFactory(
if (Context.canExperimentalCustomChecks() && custom::RegisterCustomChecks)
custom::RegisterCustomChecks(Context.getOptions(), *CheckFactories);
#endif
- for (ClangTidyModuleRegistry::entry E : ClangTidyModuleRegistry::entries()) {
+ for (const ClangTidyModuleRegistry::entry E :
+ ClangTidyModuleRegistry::entries()) {
std::unique_ptr Module = E.instantiate();
Module->addCheckFactories(*CheckFactories);
}
@@ -394,8 +398,9 @@ static CheckersList getAnalyzerCheckersAndPackages(ClangTidyContext &Context,
// Always add all core checkers if any other static analyzer check is enabled.
// This is currently necessary, as other path sensitive checks rely on the
// core checkers.
- for (StringRef CheckName : RegisteredCheckers) {
- std::string ClangTidyCheckName((AnalyzerCheckNamePrefix + CheckName).str());
+ for (const StringRef CheckName : RegisteredCheckers) {
+ const std::string ClangTidyCheckName(
+ (AnalyzerCheckNamePrefix + CheckName).str());
if (CheckName.starts_with("core") ||
Context.isCheckEnabled(ClangTidyCheckName)) {
@@ -450,8 +455,8 @@ ClangTidyASTConsumerFactory::createASTConsumer(
if (Context.canEnableModuleHeadersParsing() &&
Context.getLangOpts().Modules && OverlayFS != nullptr) {
- auto ModuleExpander =
- std::make_unique(&Compiler, OverlayFS);
+ auto ModuleExpander = std::make_unique(
+ &Compiler, *OverlayFS);
ModuleExpanderPP = ModuleExpander->getPreprocessor();
PP->addPPCallbacks(std::move(ModuleExpander));
}
@@ -504,7 +509,7 @@ std::vector ClangTidyASTConsumerFactory::getCheckNames() {
ClangTidyOptions::OptionMap ClangTidyASTConsumerFactory::getCheckOptions() {
ClangTidyOptions::OptionMap Options;
- std::vector> Checks =
+ const std::vector> Checks =
CheckFactories->createChecks(&Context);
for (const auto &Check : Checks)
Check->storeOptions(Options);
@@ -564,7 +569,7 @@ runClangTidy(clang::tidy::ClangTidyContext &Context,
std::make_shared(), BaseFS);
// Add extra arguments passed by the clang-tidy command-line.
- ArgumentsAdjuster PerFileExtraArgumentsInserter =
+ const ArgumentsAdjuster PerFileExtraArgumentsInserter =
[&Context](const CommandLineArguments &Args, StringRef Filename) {
ClangTidyOptions Opts = Context.getOptionsForFile(Filename);
CommandLineArguments AdjustedArgs = Args;
@@ -703,7 +708,7 @@ ChecksAndOptions getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers,
#if CLANG_TIDY_ENABLE_STATIC_ANALYZER
SmallString<64> Buffer(AnalyzerCheckNamePrefix);
- size_t DefSize = Buffer.size();
+ const size_t DefSize = Buffer.size();
for (const auto &AnalyzerCheck : AnalyzerOptions::getRegisteredCheckers(
AllowEnablingAnalyzerAlphaCheckers)) {
Buffer.truncate(DefSize);
diff --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
index 6e0c252a80bf8..b747657594ac0 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
@@ -161,7 +161,7 @@ ClangTidyCheck::OptionsView::getEnumInt(StringRef LocalName,
if (Iter == CheckOptions.end())
return std::nullopt;
- StringRef Value = Iter->getValue().Value;
+ const StringRef Value = Iter->getValue().Value;
StringRef Closest;
unsigned EditDistance = 3;
for (const auto &NameAndEnum : Mapping) {
@@ -173,7 +173,7 @@ ClangTidyCheck::OptionsView::getEnumInt(StringRef LocalName,
EditDistance = 0;
continue;
}
- unsigned Distance =
+ const unsigned Distance =
Value.edit_distance(NameAndEnum.second, true, EditDistance);
if (Distance < EditDistance) {
EditDistance = Distance;
diff --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.h b/clang-tools-extra/clang-tidy/ClangTidyCheck.h
index e53ae532d7e5f..905e419cdf0ca 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyCheck.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.h
@@ -458,7 +458,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
template
std::enable_if_t, std::vector>
typeEraseMapping() const {
- ArrayRef> Mapping =
+ const ArrayRef> Mapping =
OptionEnumMapping::getEnumMapping();
std::vector Result;
Result.reserve(Mapping.size());
diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index 65fd09f99ef0f..81a9f932e547d 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -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(Error.Message.FileOffset));
return diag(Error.DiagnosticName, Loc, Error.Message.Message,
static_cast(Error.DiagLevel));
@@ -214,7 +215,7 @@ bool ClangTidyContext::shouldSuppressDiagnostic(
DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info,
SmallVectorImpl &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 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::const_iterator I =
+ const llvm::DenseMap::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 Inserted =
+ const std::pair Inserted =
UniqueErrors.insert(&Error);
// Unique error, we keep it and move along.
diff --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
index c4b47a440e44b..550f7809d75f9 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -119,7 +119,7 @@ void yamlize(IO &IO, ClangTidyOptions::OptionMap &Val, bool,
yamlize(IO, NOpts->Options, true, Ctx);
} else if (isa(I.getCurrentNode())) {
IO.beginMapping();
- for (StringRef Key : IO.keys()) {
+ for (const StringRef Key : IO.keys()) {
// Requires 'llvm::yaml::IO' to accept 'StringRef'
// NOLINTNEXTLINE(bugprone-suspicious-stringview-data-usage)
IO.mapRequired(Key.data(), Val[Key].Value);
@@ -392,7 +392,7 @@ llvm::ErrorOr>
FileOptionsBaseProvider::getNormalizedAbsolutePath(llvm::StringRef Path) {
assert(FS && "FS must be set.");
llvm::SmallString<128> NormalizedAbsolutePath = {Path};
- std::error_code Err = FS->makeAbsolute(NormalizedAbsolutePath);
+ const std::error_code Err = FS->makeAbsolute(NormalizedAbsolutePath);
if (Err)
return Err;
llvm::sys::path::remove_dots(NormalizedAbsolutePath, /*remove_dot_dot=*/true);
@@ -463,7 +463,7 @@ FileOptionsProvider::getRawOptions(StringRef FileName) {
LLVM_DEBUG(llvm::dbgs() << "Getting options for file " << FileName
<< "...\n");
- llvm::ErrorOr> AbsoluteFilePath =
+ const llvm::ErrorOr> AbsoluteFilePath =
getNormalizedAbsolutePath(FileName);
if (!AbsoluteFilePath)
return {};
@@ -471,8 +471,8 @@ FileOptionsProvider::getRawOptions(StringRef FileName) {
std::vector RawOptions =
DefaultOptionsProvider::getRawOptions(AbsoluteFilePath->str());
addRawFileOptions(AbsoluteFilePath->str(), RawOptions);
- OptionsSource CommandLineOptions(OverrideOptions,
- OptionsSourceTypeCheckCommandLineOption);
+ const OptionsSource CommandLineOptions(
+ OverrideOptions, OptionsSourceTypeCheckCommandLineOption);
RawOptions.push_back(CommandLineOptions);
return RawOptions;
@@ -502,7 +502,7 @@ FileOptionsBaseProvider::tryReadConfigFile(StringRef Directory) {
llvm::ErrorOr> Text =
FS->getBufferForFile(ConfigFile);
- if (std::error_code EC = Text.getError()) {
+ if (const std::error_code EC = Text.getError()) {
llvm::errs() << "Can't read " << ConfigFile << ": " << EC.message()
<< "\n";
continue;
diff --git a/clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp b/clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp
index 8ea6b76819804..6fee154be448c 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyProfiling.cpp
@@ -59,7 +59,8 @@ void ClangTidyProfiling::storeProfileData(llvm::TimerGroup &TG) {
llvm::SmallString<256> OutputDirectory(Storage->StoreFilename);
llvm::sys::path::remove_filename(OutputDirectory);
- if (std::error_code EC = llvm::sys::fs::create_directories(OutputDirectory)) {
+ if (const std::error_code EC =
+ llvm::sys::fs::create_directories(OutputDirectory)) {
llvm::errs() << "Unable to create output directory '" << OutputDirectory
<< "': " << EC.message() << "\n";
return;
diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
index 487e5e299d132..9a4fc7a30b472 100644
--- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
+++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
@@ -65,8 +65,7 @@ class ExpandModularHeadersPPCallbacks::FileRecorder {
};
ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks(
- CompilerInstance *CI,
- IntrusiveRefCntPtr OverlayFS)
+ CompilerInstance *CI, llvm::vfs::OverlayFileSystem &OverlayFS)
: Recorder(std::make_unique()), Compiler(*CI),
InMemoryFs(new llvm::vfs::InMemoryFileSystem),
Sources(Compiler.getSourceManager()),
@@ -76,7 +75,7 @@ ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks(
LangOpts(Compiler.getLangOpts()), HSOpts(Compiler.getHeaderSearchOpts()) {
// Add a FileSystem containing the extra files needed in place of modular
// headers.
- OverlayFS->pushOverlay(InMemoryFs);
+ OverlayFS.pushOverlay(InMemoryFs);
Diags.setSourceManager(&Sources);
// FIXME: Investigate whatever is there better way to initialize DiagEngine
diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h
index aaa04107a11ec..95216368492ca 100644
--- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h
+++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLING_EXPANDMODULARHEADERSPPCALLBACKS_H_
-#define LLVM_CLANG_TOOLING_EXPANDMODULARHEADERSPPCALLBACKS_H_
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_EXPANDMODULARHEADERSPPCALLBACKS_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_EXPANDMODULARHEADERSPPCALLBACKS_H
#include "clang/Lex/HeaderSearchOptions.h"
#include "clang/Lex/PPCallbacks.h"
@@ -41,9 +41,8 @@ namespace tooling {
/// non-modular way.
class ExpandModularHeadersPPCallbacks : public PPCallbacks {
public:
- ExpandModularHeadersPPCallbacks(
- CompilerInstance *CI,
- IntrusiveRefCntPtr OverlayFS);
+ ExpandModularHeadersPPCallbacks(CompilerInstance *CI,
+ llvm::vfs::OverlayFileSystem &OverlayFS);
~ExpandModularHeadersPPCallbacks() override;
/// Returns the preprocessor that provides callbacks for the whole
@@ -144,4 +143,4 @@ class ExpandModularHeadersPPCallbacks : public PPCallbacks {
} // namespace tooling
} // namespace clang
-#endif // LLVM_CLANG_TOOLING_EXPANDMODULARHEADERSPPCALLBACKS_H_
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_EXPANDMODULARHEADERSPPCALLBACKS_H
diff --git a/clang-tools-extra/clang-tidy/FileExtensionsSet.h b/clang-tools-extra/clang-tidy/FileExtensionsSet.h
index 95c221c84da2e..f97bb64ff946e 100644
--- a/clang-tools-extra/clang-tidy/FileExtensionsSet.h
+++ b/clang-tools-extra/clang-tidy/FileExtensionsSet.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FILE_EXTENSIONS_SET_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FILE_EXTENSIONS_SET_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FILEEXTENSIONSSET_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FILEEXTENSIONSSET_H
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/StringRef.h"
@@ -16,4 +16,4 @@ namespace clang::tidy {
using FileExtensionsSet = llvm::SmallSet;
} // namespace clang::tidy
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FILE_EXTENSIONS_SET_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FILEEXTENSIONSSET_H
diff --git a/clang-tools-extra/clang-tidy/GlobList.cpp b/clang-tools-extra/clang-tidy/GlobList.cpp
index 667a25657a4c9..5d5a5f2d8d865 100644
--- a/clang-tools-extra/clang-tidy/GlobList.cpp
+++ b/clang-tools-extra/clang-tidy/GlobList.cpp
@@ -23,16 +23,17 @@ static bool consumeNegativeIndicator(StringRef &GlobList) {
// removes it and the trailing comma from the GlobList and
// returns the extracted glob.
static llvm::StringRef extractNextGlob(StringRef &GlobList) {
- StringRef UntrimmedGlob = GlobList.substr(0, GlobList.find_first_of(",\n"));
- StringRef Glob = UntrimmedGlob.trim();
+ const StringRef UntrimmedGlob =
+ GlobList.substr(0, GlobList.find_first_of(",\n"));
+ const StringRef Glob = UntrimmedGlob.trim();
GlobList = GlobList.substr(UntrimmedGlob.size() + 1);
return Glob;
}
static llvm::Regex createRegexFromGlob(StringRef &Glob) {
SmallString<128> RegexText("^");
- StringRef MetaChars("()^$|*+?.[]\\{}");
- for (char C : Glob) {
+ const StringRef MetaChars("()^$|*+?.[]\\{}");
+ for (const char C : Glob) {
if (C == '*')
RegexText.push_back('.');
else if (MetaChars.contains(C))
diff --git a/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp b/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
index ef20ee18347df..a74ab008fa7c7 100644
--- a/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
+++ b/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
@@ -134,7 +134,7 @@ static SmallVector getNoLints(StringRef Buffer) {
// Get checks, if specified.
std::optional Checks;
if (Pos < Buffer.size() && Buffer[Pos] == '(') {
- size_t ClosingBracket = Buffer.find_first_of("\n)", ++Pos);
+ const size_t ClosingBracket = Buffer.find_first_of("\n)", ++Pos);
if (ClosingBracket != StringRef::npos && Buffer[ClosingBracket] == ')') {
Checks = Buffer.slice(Pos, ClosingBracket);
Pos = ClosingBracket + 1;
@@ -183,13 +183,13 @@ static tooling::Diagnostic makeNoLintError(const SourceManager &SrcMgr,
tooling::Diagnostic Error;
Error.DiagLevel = tooling::Diagnostic::Error;
Error.DiagnosticName = "clang-tidy-nolint";
- StringRef Message =
+ const StringRef Message =
(NoLint.Type == NoLintType::NoLintBegin)
? ("unmatched 'NOLINTBEGIN' comment without a subsequent 'NOLINT"
"END' comment")
: ("unmatched 'NOLINTEND' comment without a previous 'NOLINT"
"BEGIN' comment");
- SourceLocation Loc = SrcMgr.getComposedLoc(File, NoLint.Pos);
+ const SourceLocation Loc = SrcMgr.getComposedLoc(File, NoLint.Pos);
Error.Message = tooling::DiagnosticMessage(Message, SrcMgr, Loc);
return Error;
}
@@ -294,8 +294,8 @@ bool NoLintDirectiveHandler::Impl::diagHasNoLintInMacro(
// this line.
static std::pair getLineStartAndEnd(StringRef Buffer,
size_t From) {
- size_t StartPos = Buffer.find_last_of('\n', From) + 1;
- size_t EndPos = std::min(Buffer.find('\n', From), Buffer.size());
+ const size_t StartPos = Buffer.find_last_of('\n', From) + 1;
+ const size_t EndPos = std::min(Buffer.find('\n', From), Buffer.size());
return {StartPos, EndPos};
}
diff --git a/clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h b/clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h
index 2ae3c00f7ee3e..982774ca4db5b 100644
--- a/clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h
+++ b/clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h
@@ -6,6 +6,9 @@
//
//===----------------------------------------------------------------------===//
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_ABSEILMATCHER_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_ABSEILMATCHER_H
+
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include
@@ -31,7 +34,7 @@ AST_POLYMORPHIC_MATCHER(
isInAbseilFile, AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc,
NestedNameSpecifierLoc)) {
auto &SourceManager = Finder->getASTContext().getSourceManager();
- SourceLocation Loc = SourceManager.getSpellingLoc(Node.getBeginLoc());
+ const SourceLocation Loc = SourceManager.getSpellingLoc(Node.getBeginLoc());
if (Loc.isInvalid())
return false;
OptionalFileEntryRef FileEntry =
@@ -42,7 +45,7 @@ AST_POLYMORPHIC_MATCHER(
// [absl-library] is AbseilLibraries list entry.
StringRef Path = FileEntry->getName();
static constexpr llvm::StringLiteral AbslPrefix("absl/");
- size_t PrefixPosition = Path.find(AbslPrefix);
+ const size_t PrefixPosition = Path.find(AbslPrefix);
if (PrefixPosition == StringRef::npos)
return false;
Path = Path.drop_front(PrefixPosition + AbslPrefix.size());
@@ -57,3 +60,5 @@ AST_POLYMORPHIC_MATCHER(
}
} // namespace clang::ast_matchers
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_ABSEILMATCHER_H
diff --git a/clang-tools-extra/clang-tidy/abseil/DurationAdditionCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationAdditionCheck.cpp
index 03f78f1c96252..421e5973d4fe0 100644
--- a/clang-tools-extra/clang-tidy/abseil/DurationAdditionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/DurationAdditionCheck.cpp
@@ -41,7 +41,7 @@ void DurationAdditionCheck::check(const MatchFinder::MatchResult &Result) {
if (!Scale)
return;
- llvm::StringRef TimeFactory = getTimeInverseForScale(*Scale);
+ const llvm::StringRef TimeFactory = getTimeInverseForScale(*Scale);
FixItHint Hint;
if (Call == Binop->getLHS()->IgnoreParenImpCasts()) {
diff --git a/clang-tools-extra/clang-tidy/abseil/DurationAdditionCheck.h b/clang-tools-extra/clang-tidy/abseil/DurationAdditionCheck.h
index b728118c3da03..f5bab53035f87 100644
--- a/clang-tools-extra/clang-tidy/abseil/DurationAdditionCheck.h
+++ b/clang-tools-extra/clang-tidy/abseil/DurationAdditionCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMEADDITIONCHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMEADDITIONCHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_DURATIONADDITIONCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_DURATIONADDITIONCHECK_H
#include "../ClangTidyCheck.h"
@@ -31,4 +31,4 @@ class DurationAdditionCheck : public ClangTidyCheck {
} // namespace clang::tidy::abseil
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMEADDITIONCHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_DURATIONADDITIONCHECK_H
diff --git a/clang-tools-extra/clang-tidy/abseil/DurationComparisonCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationComparisonCheck.cpp
index 16a244b7e9997..f00877754f952 100644
--- a/clang-tools-extra/clang-tidy/abseil/DurationComparisonCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/DurationComparisonCheck.cpp
@@ -38,9 +38,9 @@ void DurationComparisonCheck::check(const MatchFinder::MatchResult &Result) {
// if nothing needs to be done.
if (isInMacro(Result, Binop->getLHS()) || isInMacro(Result, Binop->getRHS()))
return;
- std::string LhsReplacement =
+ const std::string LhsReplacement =
rewriteExprFromNumberToDuration(Result, *Scale, Binop->getLHS());
- std::string RhsReplacement =
+ const std::string RhsReplacement =
rewriteExprFromNumberToDuration(Result, *Scale, Binop->getRHS());
diag(Binop->getBeginLoc(), "perform comparison in the duration domain")
diff --git a/clang-tools-extra/clang-tidy/abseil/DurationConversionCastCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationConversionCastCheck.cpp
index 11d6017c22e9d..ef06a9e2ba572 100644
--- a/clang-tools-extra/clang-tidy/abseil/DurationConversionCastCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/DurationConversionCastCheck.cpp
@@ -41,7 +41,7 @@ void DurationConversionCastCheck::check(
const auto *FuncDecl = Result.Nodes.getNodeAs("func_decl");
const auto *Arg = Result.Nodes.getNodeAs("arg");
- StringRef ConversionFuncName = FuncDecl->getName();
+ const StringRef ConversionFuncName = FuncDecl->getName();
std::optional Scale =
getScaleForDurationInverse(ConversionFuncName);
@@ -51,7 +51,8 @@ void DurationConversionCastCheck::check(
// Casting a double to an integer.
if (MatchedCast->getTypeAsWritten()->isIntegerType() &&
ConversionFuncName.contains("Double")) {
- llvm::StringRef NewFuncName = getDurationInverseForScale(*Scale).second;
+ const llvm::StringRef NewFuncName =
+ getDurationInverseForScale(*Scale).second;
diag(MatchedCast->getBeginLoc(),
"duration should be converted directly to an integer rather than "
@@ -66,7 +67,8 @@ void DurationConversionCastCheck::check(
// Casting an integer to a double.
if (MatchedCast->getTypeAsWritten()->isRealFloatingType() &&
ConversionFuncName.contains("Int64")) {
- llvm::StringRef NewFuncName = getDurationInverseForScale(*Scale).first;
+ const llvm::StringRef NewFuncName =
+ getDurationInverseForScale(*Scale).first;
diag(MatchedCast->getBeginLoc(), "duration should be converted directly to "
"a floating-point number rather than "
diff --git a/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp
index 334629767aff2..9e403fb8be3dd 100644
--- a/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp
@@ -158,7 +158,7 @@ void DurationFactoryScaleCheck::check(const MatchFinder::MatchResult &Result) {
if (!MaybeScale)
return;
- DurationScale Scale = *MaybeScale;
+ const DurationScale Scale = *MaybeScale;
const Expr *Remainder = nullptr;
std::optional NewScale;
diff --git a/clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp b/clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp
index ee1979658aaed..a78d07d2e5861 100644
--- a/clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp
@@ -20,7 +20,7 @@ namespace clang::tidy::abseil {
/// Returns an integer if the fractional part of a `FloatingLiteral` is `0`.
static std::optional
truncateIfIntegral(const FloatingLiteral &FloatLiteral) {
- double Value = FloatLiteral.getValueAsApproximateDouble();
+ const double Value = FloatLiteral.getValueAsApproximateDouble();
if (std::fmod(Value, 1) == 0) {
if (Value >= static_cast(1U << 31))
return std::nullopt;
@@ -69,7 +69,7 @@ rewriteInverseDurationCall(const MatchFinder::MatchResult &Result,
static std::optional
rewriteInverseTimeCall(const MatchFinder::MatchResult &Result,
DurationScale Scale, const Expr &Node) {
- llvm::StringRef InverseFunction = getTimeInverseForScale(Scale);
+ const llvm::StringRef InverseFunction = getTimeInverseForScale(Scale);
if (const auto *MaybeCallArg = selectFirst(
"e", match(callExpr(callee(functionDecl(hasName(InverseFunction))),
hasArgument(0, expr().bind("e"))),
diff --git a/clang-tools-extra/clang-tidy/abseil/DurationSubtractionCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationSubtractionCheck.cpp
index c5d93ad51ad17..42a7df496f6ad 100644
--- a/clang-tools-extra/clang-tidy/abseil/DurationSubtractionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/DurationSubtractionCheck.cpp
@@ -41,7 +41,7 @@ void DurationSubtractionCheck::check(const MatchFinder::MatchResult &Result) {
if (!Scale)
return;
- std::string RhsReplacement =
+ const std::string RhsReplacement =
rewriteExprFromNumberToDuration(Result, *Scale, Binop->getRHS());
const Expr *LhsArg = Result.Nodes.getNodeAs("lhs_arg");
diff --git a/clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp
index 805d7dacd4eec..5867fb630315d 100644
--- a/clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp
@@ -19,10 +19,10 @@ namespace clang::tidy::abseil {
void DurationUnnecessaryConversionCheck::registerMatchers(MatchFinder *Finder) {
for (const auto &Scale : {"Hours", "Minutes", "Seconds", "Milliseconds",
"Microseconds", "Nanoseconds"}) {
- std::string DurationFactory = (llvm::Twine("::absl::") + Scale).str();
- std::string FloatConversion =
+ const std::string DurationFactory = (llvm::Twine("::absl::") + Scale).str();
+ const std::string FloatConversion =
(llvm::Twine("::absl::ToDouble") + Scale).str();
- std::string IntegerConversion =
+ const std::string IntegerConversion =
(llvm::Twine("::absl::ToInt64") + Scale).str();
// Matcher which matches the current scale's factory with a `1` argument,
diff --git a/clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.h b/clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.h
index 59af8968e8b38..f5d25116b5bc1 100644
--- a/clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.h
+++ b/clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMEDOUBLECONVERSIONCHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMEDOUBLECONVERSIONCHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_DURATIONUNNECESSARYCONVERSIONCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_DURATIONUNNECESSARYCONVERSIONCHECK_H
#include "../ClangTidyCheck.h"
@@ -31,4 +31,4 @@ class DurationUnnecessaryConversionCheck : public ClangTidyCheck {
} // namespace clang::tidy::abseil
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMEDOUBLECONVERSIONCHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_DURATIONUNNECESSARYCONVERSIONCHECK_H
diff --git a/clang-tools-extra/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp b/clang-tools-extra/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
index d9f6551739d9e..0827526ba3b5d 100644
--- a/clang-tools-extra/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
@@ -29,7 +29,7 @@ makeCharacterLiteral(const StringLiteral *Literal, const ASTContext &Context) {
assert(Literal->getCharByteWidth() == 1 &&
"StrSplit doesn't support wide char");
std::string Result = clang::tooling::fixit::getText(*Literal, Context).str();
- bool IsRawStringLiteral = StringRef(Result).starts_with(R"(R")");
+ const bool IsRawStringLiteral = StringRef(Result).starts_with(R"(R")");
// Since raw string literal might contain unescaped non-printable characters,
// we normalize them using `StringLiteral::outputString`.
if (IsRawStringLiteral) {
diff --git a/clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.cpp b/clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.cpp
index c090e5ac54222..5f4cb66424700 100644
--- a/clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.cpp
@@ -32,7 +32,7 @@ void NoInternalDependenciesCheck::check(
const auto *InternalDependency =
Result.Nodes.getNodeAs("InternalDep");
- SourceLocation LocAtFault =
+ const SourceLocation LocAtFault =
Result.SourceManager->getSpellingLoc(InternalDependency->getBeginLoc());
if (!LocAtFault.isValid())
diff --git a/clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.h b/clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.h
index 2911a1ad14ae8..22918311398f1 100644
--- a/clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.h
+++ b/clang-tools-extra/clang-tidy/abseil/NoInternalDependenciesCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_NOINTERNALDEPSCHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_NOINTERNALDEPSCHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_NOINTERNALDEPENDENCIESCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_NOINTERNALDEPENDENCIESCHECK_H
#include "../ClangTidyCheck.h"
@@ -31,4 +31,4 @@ class NoInternalDependenciesCheck : public ClangTidyCheck {
} // namespace clang::tidy::abseil
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_NOINTERNALDEPSCHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_NOINTERNALDEPENDENCIESCHECK_H
diff --git a/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp b/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
index 92d63057caf65..e1063c4f8a46e 100644
--- a/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
@@ -92,7 +92,7 @@ void StringFindStartswithCheck::check(const MatchFinder::MatchResult &Result) {
const auto *FindFun = Result.Nodes.getNodeAs("findfun");
assert(FindFun != nullptr);
- bool Rev = FindFun->getName().contains("rfind");
+ const bool Rev = FindFun->getName().contains("rfind");
if (ComparisonExpr->getBeginLoc().isMacroID())
return;
@@ -107,7 +107,7 @@ void StringFindStartswithCheck::check(const MatchFinder::MatchResult &Result) {
Context.getLangOpts());
// Create the StartsWith string, negating if comparison was "!=".
- bool Neg = ComparisonExpr->getOpcode() == BO_NE;
+ const bool Neg = ComparisonExpr->getOpcode() == BO_NE;
// Create the warning message and a FixIt hint replacing the original expr.
auto Diagnostic =
diff --git a/clang-tools-extra/clang-tidy/abseil/TimeComparisonCheck.cpp b/clang-tools-extra/clang-tidy/abseil/TimeComparisonCheck.cpp
index 7a97a1895ad02..5d80b16239838 100644
--- a/clang-tools-extra/clang-tidy/abseil/TimeComparisonCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/TimeComparisonCheck.cpp
@@ -39,9 +39,9 @@ void TimeComparisonCheck::check(const MatchFinder::MatchResult &Result) {
// want to handle the case of rewriting both sides. This is much simpler if
// we unconditionally try and rewrite both, and let the rewriter determine
// if nothing needs to be done.
- std::string LhsReplacement =
+ const std::string LhsReplacement =
rewriteExprFromNumberToTime(Result, *Scale, Binop->getLHS());
- std::string RhsReplacement =
+ const std::string RhsReplacement =
rewriteExprFromNumberToTime(Result, *Scale, Binop->getRHS());
diag(Binop->getBeginLoc(), "perform comparison in the time domain")
diff --git a/clang-tools-extra/clang-tidy/abseil/TimeComparisonCheck.h b/clang-tools-extra/clang-tidy/abseil/TimeComparisonCheck.h
index 703d9514e8c07..74a877a84d9e8 100644
--- a/clang-tools-extra/clang-tidy/abseil/TimeComparisonCheck.h
+++ b/clang-tools-extra/clang-tidy/abseil/TimeComparisonCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMECOMPARECHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMECOMPARECHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMECOMPARISONCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMECOMPARISONCHECK_H
#include "../ClangTidyCheck.h"
@@ -31,4 +31,4 @@ class TimeComparisonCheck : public ClangTidyCheck {
} // namespace clang::tidy::abseil
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMECOMPARECHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMECOMPARISONCHECK_H
diff --git a/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp b/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp
index 228d974cd5e23..4ae49d285930d 100644
--- a/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp
@@ -93,7 +93,7 @@ void TimeSubtractionCheck::emitDiagnostic(const Expr *Node,
void TimeSubtractionCheck::registerMatchers(MatchFinder *Finder) {
for (const char *ScaleName :
{"Hours", "Minutes", "Seconds", "Millis", "Micros", "Nanos"}) {
- std::string TimeInverse = (llvm::Twine("ToUnix") + ScaleName).str();
+ const std::string TimeInverse = (llvm::Twine("ToUnix") + ScaleName).str();
std::optional Scale = getScaleForTimeInverse(TimeInverse);
assert(Scale && "Unknown scale encountered");
@@ -127,7 +127,7 @@ void TimeSubtractionCheck::registerMatchers(MatchFinder *Finder) {
void TimeSubtractionCheck::check(const MatchFinder::MatchResult &Result) {
const auto *BinOp = Result.Nodes.getNodeAs("binop");
- std::string InverseName =
+ const std::string InverseName =
Result.Nodes.getNodeAs("func_decl")->getNameAsString();
if (insideMacroDefinition(Result, BinOp->getSourceRange()))
return;
@@ -144,7 +144,7 @@ void TimeSubtractionCheck::check(const MatchFinder::MatchResult &Result) {
// We're working with the first case of matcher, and need to replace the
// entire 'Duration' factory call. (Which also means being careful about
// our order-of-operations and optionally putting in some parenthesis.
- bool NeedParens = parensRequired(Result, OuterCall);
+ const bool NeedParens = parensRequired(Result, OuterCall);
emitDiagnostic(
OuterCall,
@@ -169,7 +169,7 @@ void TimeSubtractionCheck::check(const MatchFinder::MatchResult &Result) {
// converts it from the inverse to a Duration. In this case, we replace
// the outer with just the subtraction expression, which gives the right
// type and scale, taking care again about parenthesis.
- bool NeedParens = parensRequired(Result, MaybeCallArg);
+ const bool NeedParens = parensRequired(Result, MaybeCallArg);
emitDiagnostic(
MaybeCallArg,
diff --git a/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp b/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
index 8b197e5b939e7..1a6ff30fc8d96 100644
--- a/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
@@ -117,10 +117,10 @@ void UpgradeDurationConversionsCheck::check(
"implicit conversion to 'int64_t' is deprecated in this context; use an "
"explicit cast instead";
- TraversalKindScope RAII(*Result.Context, TK_AsIs);
+ const TraversalKindScope RAII(*Result.Context, TK_AsIs);
const auto *ArgExpr = Result.Nodes.getNodeAs("arg");
- SourceLocation Loc = ArgExpr->getBeginLoc();
+ const SourceLocation Loc = ArgExpr->getBeginLoc();
const auto *OuterExpr = Result.Nodes.getNodeAs("OuterExpr");
@@ -139,13 +139,13 @@ void UpgradeDurationConversionsCheck::check(
// We gather source locations from template matches not in template
// instantiations for future matches.
- internal::Matcher IsInsideTemplate =
+ const internal::Matcher IsInsideTemplate =
hasAncestor(decl(anyOf(classTemplateDecl(), functionTemplateDecl())));
if (!match(IsInsideTemplate, *ArgExpr, *Result.Context).empty())
MatchedTemplateLocations.insert(Loc);
- DiagnosticBuilder Diag = diag(Loc, Message);
- CharSourceRange SourceRange = Lexer::makeFileCharRange(
+ const DiagnosticBuilder Diag = diag(Loc, Message);
+ const CharSourceRange SourceRange = Lexer::makeFileCharRange(
CharSourceRange::getTokenRange(ArgExpr->getSourceRange()),
*Result.SourceManager, Result.Context->getLangOpts());
if (SourceRange.isInvalid())
diff --git a/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp b/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp
index 49ba17ce643fe..519d90914580f 100644
--- a/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp
+++ b/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp
@@ -76,7 +76,7 @@ void IdDependentBackwardBranchCheck::registerMatchers(MatchFinder *Finder) {
this);
}
-IdDependentBackwardBranchCheck::IdDependencyRecord *
+const IdDependentBackwardBranchCheck::IdDependencyRecord *
IdDependentBackwardBranchCheck::hasIdDepVar(const Expr *Expression) {
if (!Expression)
return nullptr;
@@ -94,12 +94,12 @@ IdDependentBackwardBranchCheck::hasIdDepVar(const Expr *Expression) {
}
for (const auto *Child : Expression->children())
if (const auto *ChildExpression = dyn_cast_if_present(Child))
- if (IdDependencyRecord *Result = hasIdDepVar(ChildExpression))
+ if (const IdDependencyRecord *Result = hasIdDepVar(ChildExpression))
return Result;
return nullptr;
}
-IdDependentBackwardBranchCheck::IdDependencyRecord *
+const IdDependentBackwardBranchCheck::IdDependencyRecord *
IdDependentBackwardBranchCheck::hasIdDepField(const Expr *Expression) {
if (!Expression)
return nullptr;
@@ -116,7 +116,7 @@ IdDependentBackwardBranchCheck::hasIdDepField(const Expr *Expression) {
}
for (const auto *Child : Expression->children())
if (const auto *ChildExpression = dyn_cast_if_present(Child))
- if (IdDependencyRecord *Result = hasIdDepField(ChildExpression))
+ if (const IdDependencyRecord *Result = hasIdDepField(ChildExpression))
return Result;
return nullptr;
}
@@ -239,7 +239,7 @@ void IdDependentBackwardBranchCheck::check(
const auto *Loop = Result.Nodes.getNodeAs("backward_branch");
if (!Loop)
return;
- LoopType Type = getLoopType(Loop);
+ const LoopType Type = getLoopType(Loop);
if (CondExpr) {
if (IDCall) { // Conditional expression calls an ID function directly.
diag(CondExpr->getBeginLoc(),
@@ -249,8 +249,8 @@ void IdDependentBackwardBranchCheck::check(
return;
}
// Conditional expression has DeclRefExpr(s), check ID-dependency.
- IdDependencyRecord *IdDepVar = hasIdDepVar(CondExpr);
- IdDependencyRecord *IdDepField = hasIdDepField(CondExpr);
+ const IdDependencyRecord *IdDepVar = hasIdDepVar(CondExpr);
+ const IdDependencyRecord *IdDepField = hasIdDepField(CondExpr);
if (IdDepVar) {
diag(CondExpr->getBeginLoc(),
"backward branch (%select{do|while|for}0 loop) is ID-dependent due "
diff --git a/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.h b/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.h
index b777918ab7e7b..297e7751e4f49 100644
--- a/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.h
+++ b/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.h
@@ -44,10 +44,10 @@ class IdDependentBackwardBranchCheck : public ClangTidyCheck {
std::map IdDepFieldsMap;
/// Returns an IdDependencyRecord if the Expression contains an ID-dependent
/// variable, returns a nullptr otherwise.
- IdDependencyRecord *hasIdDepVar(const Expr *Expression);
+ const IdDependencyRecord *hasIdDepVar(const Expr *Expression);
/// Returns an IdDependencyRecord if the Expression contains an ID-dependent
/// field, returns a nullptr otherwise.
- IdDependencyRecord *hasIdDepField(const Expr *Expression);
+ const IdDependencyRecord *hasIdDepField(const Expr *Expression);
/// Stores the location an ID-dependent variable is created from a call to
/// an ID function in IdDepVarsMap.
void saveIdDepVar(const Stmt *Statement, const VarDecl *Variable);
diff --git a/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp b/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp
index 4c740e31ae7be..8aa23b8fc7b11 100644
--- a/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp
@@ -77,7 +77,7 @@ void KernelNameRestrictionPPCallbacks::EndOfMainFile() {
// Check main file for restricted names.
OptionalFileEntryRef Entry = SM.getFileEntryRefForID(SM.getMainFileID());
- StringRef FileName = llvm::sys::path::filename(Entry->getName());
+ const StringRef FileName = llvm::sys::path::filename(Entry->getName());
if (fileNameIsRestricted(FileName))
Check.diag(SM.getLocForStartOfFile(SM.getMainFileID()),
"compiling '%0' may cause additional compilation errors due "
@@ -90,7 +90,7 @@ void KernelNameRestrictionPPCallbacks::EndOfMainFile() {
// Check included files for restricted names.
for (const IncludeDirective &ID : IncludeDirectives) {
- StringRef FileName = llvm::sys::path::filename(ID.FileName);
+ const StringRef FileName = llvm::sys::path::filename(ID.FileName);
if (fileNameIsRestricted(FileName))
Check.diag(ID.Loc,
"including '%0' may cause additional compilation errors due "
diff --git a/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.h b/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.h
index 182d10b5539e5..441cf36446c9a 100644
--- a/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.h
+++ b/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_KERNEL_NAME_RESTRICTION_CHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_KERNEL_NAME_RESTRICTION_CHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_KERNELNAMERESTRICTIONCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_KERNELNAMERESTRICTIONCHECK_H
#include "../ClangTidyCheck.h"
@@ -28,4 +28,4 @@ class KernelNameRestrictionCheck : public ClangTidyCheck {
} // namespace clang::tidy::altera
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_KERNEL_NAME_RESTRICTION_CHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_KERNELNAMERESTRICTIONCHECK_H
diff --git a/clang-tools-extra/clang-tidy/altera/SingleWorkItemBarrierCheck.h b/clang-tools-extra/clang-tidy/altera/SingleWorkItemBarrierCheck.h
index dab3dbce50371..dcfefcb0a1b29 100644
--- a/clang-tools-extra/clang-tidy/altera/SingleWorkItemBarrierCheck.h
+++ b/clang-tools-extra/clang-tidy/altera/SingleWorkItemBarrierCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_SINGLE_WORK_ITEM_BARRIER_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_SINGLE_WORK_ITEM_BARRIER_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_SINGLEWORKITEMBARRIERCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_SINGLEWORKITEMBARRIERCHECK_H
#include "../ClangTidyCheck.h"
@@ -33,4 +33,4 @@ class SingleWorkItemBarrierCheck : public ClangTidyCheck {
} // namespace clang::tidy::altera
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_SINGLE_WORK_ITEM_BARRIER_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ALTERA_SINGLEWORKITEMBARRIERCHECK_H
diff --git a/clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp b/clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
index 0a19378949f46..2b1312c8967da 100644
--- a/clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
+++ b/clang-tools-extra/clang-tidy/altera/StructPackAlignCheck.cpp
@@ -60,10 +60,10 @@ void StructPackAlignCheck::check(const MatchFinder::MatchResult &Result) {
// For each StructField, record how big it is (in bits).
// Would be good to use a pair of to advise a better
// packing order.
- QualType StructFieldTy = StructField->getType();
+ const QualType StructFieldTy = StructField->getType();
if (StructFieldTy->isIncompleteType())
return;
- unsigned int StructFieldWidth =
+ const unsigned int StructFieldWidth =
(unsigned int)Result.Context->getTypeInfo(StructFieldTy.getTypePtr())
.Width;
FieldSizes.emplace_back(StructFieldWidth, StructField->getFieldIndex());
@@ -72,21 +72,22 @@ void StructPackAlignCheck::check(const MatchFinder::MatchResult &Result) {
TotalBitSize += StructFieldWidth;
}
- uint64_t CharSize = Result.Context->getCharWidth();
- CharUnits CurrSize = Result.Context->getASTRecordLayout(Struct).getSize();
- CharUnits MinByteSize =
+ const uint64_t CharSize = Result.Context->getCharWidth();
+ const CharUnits CurrSize =
+ Result.Context->getASTRecordLayout(Struct).getSize();
+ const CharUnits MinByteSize =
CharUnits::fromQuantity(std::max(
std::ceil(static_cast(TotalBitSize) / CharSize), 1));
- CharUnits MaxAlign = CharUnits::fromQuantity(
+ const CharUnits MaxAlign = CharUnits::fromQuantity(
std::ceil((float)Struct->getMaxAlignment() / CharSize));
- CharUnits CurrAlign =
+ const CharUnits CurrAlign =
Result.Context->getASTRecordLayout(Struct).getAlignment();
- CharUnits NewAlign = computeRecommendedAlignment(MinByteSize);
+ const CharUnits NewAlign = computeRecommendedAlignment(MinByteSize);
- bool IsPacked = Struct->hasAttr();
- bool NeedsPacking = (MinByteSize < CurrSize) && (MaxAlign != NewAlign) &&
- (CurrSize != NewAlign);
- bool NeedsAlignment = CurrAlign.getQuantity() != NewAlign.getQuantity();
+ const bool IsPacked = Struct->hasAttr();
+ const bool NeedsPacking = (MinByteSize < CurrSize) &&
+ (MaxAlign != NewAlign) && (CurrSize != NewAlign);
+ const bool NeedsAlignment = CurrAlign.getQuantity() != NewAlign.getQuantity();
if (!NeedsAlignment && !NeedsPacking)
return;
@@ -111,7 +112,8 @@ void StructPackAlignCheck::check(const MatchFinder::MatchResult &Result) {
FixItHint FixIt;
auto *Attribute = Struct->getAttr();
- std::string NewAlignQuantity = std::to_string((int)NewAlign.getQuantity());
+ const std::string NewAlignQuantity =
+ std::to_string((int)NewAlign.getQuantity());
if (Attribute) {
FixIt = FixItHint::CreateReplacement(
Attribute->getRange(),
diff --git a/clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp b/clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp
index e90cdd00eb1fe..b0cd4cdb41e91 100644
--- a/clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp
@@ -127,7 +127,7 @@ bool UnrollLoopsCheck::hasKnownBounds(const Stmt *Statement,
if (const auto *InitDeclStatement = dyn_cast(Initializer)) {
if (const auto *VariableDecl =
dyn_cast(InitDeclStatement->getSingleDecl())) {
- APValue *Evaluation = VariableDecl->evaluateValue();
+ const APValue *Evaluation = VariableDecl->evaluateValue();
if (!Evaluation || !Evaluation->hasValue())
return false;
}
diff --git a/clang-tools-extra/clang-tidy/android/CloexecAccept4Check.h b/clang-tools-extra/clang-tidy/android/CloexecAccept4Check.h
index 02c4e0056ea15..5637fc8bb350e 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecAccept4Check.h
+++ b/clang-tools-extra/clang-tidy/android/CloexecAccept4Check.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_ACCEPT4_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_ACCEPT4_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECACCEPT4CHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECACCEPT4CHECK_H
#include "CloexecCheck.h"
@@ -27,4 +27,4 @@ class CloexecAccept4Check : public CloexecCheck {
} // namespace clang::tidy::android
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_ACCEPT4_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECACCEPT4CHECK_H
diff --git a/clang-tools-extra/clang-tidy/android/CloexecAcceptCheck.cpp b/clang-tools-extra/clang-tidy/android/CloexecAcceptCheck.cpp
index 9cd888cca023b..a624523b18137 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecAcceptCheck.cpp
+++ b/clang-tools-extra/clang-tidy/android/CloexecAcceptCheck.cpp
@@ -26,10 +26,11 @@ void CloexecAcceptCheck::registerMatchers(MatchFinder *Finder) {
}
void CloexecAcceptCheck::check(const MatchFinder::MatchResult &Result) {
- std::string ReplacementText = (Twine("accept4(") + getSpellingArg(Result, 0) +
- ", " + getSpellingArg(Result, 1) + ", " +
- getSpellingArg(Result, 2) + ", SOCK_CLOEXEC)")
- .str();
+ const std::string ReplacementText =
+ (Twine("accept4(") + getSpellingArg(Result, 0) + ", " +
+ getSpellingArg(Result, 1) + ", " + getSpellingArg(Result, 2) +
+ ", SOCK_CLOEXEC)")
+ .str();
replaceFunc(
Result,
diff --git a/clang-tools-extra/clang-tidy/android/CloexecAcceptCheck.h b/clang-tools-extra/clang-tidy/android/CloexecAcceptCheck.h
index 4540f938fd478..332a97ace91a4 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecAcceptCheck.h
+++ b/clang-tools-extra/clang-tidy/android/CloexecAcceptCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_ACCEPT_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_ACCEPT_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECACCEPTCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECACCEPTCHECK_H
#include "CloexecCheck.h"
@@ -27,4 +27,4 @@ class CloexecAcceptCheck : public CloexecCheck {
} // namespace clang::tidy::android
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_ACCEPT_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECACCEPTCHECK_H
diff --git a/clang-tools-extra/clang-tidy/android/CloexecCheck.cpp b/clang-tools-extra/clang-tidy/android/CloexecCheck.cpp
index 48c54c0ae02c3..ff86fc52879d9 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecCheck.cpp
+++ b/clang-tools-extra/clang-tidy/android/CloexecCheck.cpp
@@ -30,12 +30,13 @@ static std::string buildFixMsgForStringFlag(const Expr *Arg,
" \"" + Twine(Mode) + "\"")
.str();
- StringRef SR = cast(Arg->IgnoreParenCasts())->getString();
+ const StringRef SR =
+ cast(Arg->IgnoreParenCasts())->getString();
return ("\"" + SR + Twine(Mode) + "\"").str();
}
void CloexecCheck::registerMatchersImpl(
- MatchFinder *Finder, internal::Matcher Function) {
+ MatchFinder *Finder, const internal::Matcher &Function) {
// We assume all the checked APIs are C functions.
Finder->addMatcher(
callExpr(
@@ -49,14 +50,14 @@ void CloexecCheck::insertMacroFlag(const MatchFinder::MatchResult &Result,
const auto *MatchedCall = Result.Nodes.getNodeAs(FuncBindingStr);
const auto *FlagArg = MatchedCall->getArg(ArgPos);
const auto *FD = Result.Nodes.getNodeAs(FuncDeclBindingStr);
- SourceManager &SM = *Result.SourceManager;
+ const SourceManager &SM = *Result.SourceManager;
if (utils::exprHasBitFlagWithSpelling(FlagArg->IgnoreParenCasts(), SM,
Result.Context->getLangOpts(),
MacroFlag))
return;
- SourceLocation EndLoc =
+ const SourceLocation EndLoc =
Lexer::getLocForEndOfToken(SM.getFileLoc(FlagArg->getEndLoc()), 0, SM,
Result.Context->getLangOpts());
@@ -84,7 +85,7 @@ void CloexecCheck::insertStringFlag(
if (!ModeStr || ModeStr->getString().contains(Mode))
return;
- std::string ReplacementText = buildFixMsgForStringFlag(
+ const std::string ReplacementText = buildFixMsgForStringFlag(
ModeArg, *Result.SourceManager, Result.Context->getLangOpts(), Mode);
diag(ModeArg->getBeginLoc(), "use %0 mode '%1' to set O_CLOEXEC")
diff --git a/clang-tools-extra/clang-tidy/android/CloexecCheck.h b/clang-tools-extra/clang-tidy/android/CloexecCheck.h
index 858d96ab45b61..a6dcb57d488da 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecCheck.h
+++ b/clang-tools-extra/clang-tidy/android/CloexecCheck.h
@@ -12,8 +12,8 @@
///
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECCHECK_H
#include "../ClangTidyCheck.h"
@@ -29,9 +29,9 @@ class CloexecCheck : public ClangTidyCheck {
: ClangTidyCheck(Name, Context) {}
protected:
- void
- registerMatchersImpl(ast_matchers::MatchFinder *Finder,
- ast_matchers::internal::Matcher Function);
+ void registerMatchersImpl(
+ ast_matchers::MatchFinder *Finder,
+ const ast_matchers::internal::Matcher &Function);
/// Currently, we have three types of fixes.
///
@@ -97,4 +97,4 @@ class CloexecCheck : public ClangTidyCheck {
} // namespace clang::tidy::android
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECCHECK_H
diff --git a/clang-tools-extra/clang-tidy/android/CloexecCreatCheck.h b/clang-tools-extra/clang-tidy/android/CloexecCreatCheck.h
index ee2f51abf05fc..d7d2b42049cd8 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecCreatCheck.h
+++ b/clang-tools-extra/clang-tidy/android/CloexecCreatCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_CREAT_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_CREAT_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECCREATCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECCREATCHECK_H
#include "CloexecCheck.h"
@@ -27,4 +27,4 @@ class CloexecCreatCheck : public CloexecCheck {
} // namespace clang::tidy::android
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_CREAT_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECCREATCHECK_H
diff --git a/clang-tools-extra/clang-tidy/android/CloexecDupCheck.cpp b/clang-tools-extra/clang-tidy/android/CloexecDupCheck.cpp
index 5ac1b6fb632e1..5db57461a5909 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecDupCheck.cpp
+++ b/clang-tools-extra/clang-tidy/android/CloexecDupCheck.cpp
@@ -20,7 +20,7 @@ void CloexecDupCheck::registerMatchers(MatchFinder *Finder) {
}
void CloexecDupCheck::check(const MatchFinder::MatchResult &Result) {
- std::string ReplacementText =
+ const std::string ReplacementText =
(Twine("fcntl(") + getSpellingArg(Result, 0) + ", F_DUPFD_CLOEXEC)")
.str();
diff --git a/clang-tools-extra/clang-tidy/android/CloexecDupCheck.h b/clang-tools-extra/clang-tidy/android/CloexecDupCheck.h
index f5699685ed086..4eae507b99b10 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecDupCheck.h
+++ b/clang-tools-extra/clang-tidy/android/CloexecDupCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_DUP_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_DUP_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECDUPCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECDUPCHECK_H
#include "CloexecCheck.h"
@@ -28,4 +28,4 @@ class CloexecDupCheck : public CloexecCheck {
} // namespace clang::tidy::android
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_DUP_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECDUPCHECK_H
diff --git a/clang-tools-extra/clang-tidy/android/CloexecEpollCreate1Check.h b/clang-tools-extra/clang-tidy/android/CloexecEpollCreate1Check.h
index f467b87a6cf70..03a529f02a6d7 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecEpollCreate1Check.h
+++ b/clang-tools-extra/clang-tidy/android/CloexecEpollCreate1Check.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_EPOLL_CREATE1_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_EPOLL_CREATE1_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECEPOLLCREATE1CHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECEPOLLCREATE1CHECK_H
#include "CloexecCheck.h"
@@ -27,4 +27,4 @@ class CloexecEpollCreate1Check : public CloexecCheck {
} // namespace clang::tidy::android
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_EPOLL_CREATE1_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECEPOLLCREATE1CHECK_H
diff --git a/clang-tools-extra/clang-tidy/android/CloexecEpollCreateCheck.h b/clang-tools-extra/clang-tidy/android/CloexecEpollCreateCheck.h
index a8d17c82d457d..243b9bd7b1317 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecEpollCreateCheck.h
+++ b/clang-tools-extra/clang-tidy/android/CloexecEpollCreateCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_EPOLL_CREATE_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_EPOLL_CREATE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECEPOLLCREATECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECEPOLLCREATECHECK_H
#include "CloexecCheck.h"
@@ -27,4 +27,4 @@ class CloexecEpollCreateCheck : public CloexecCheck {
} // namespace clang::tidy::android
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_EPOLL_CREATE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECEPOLLCREATECHECK_H
diff --git a/clang-tools-extra/clang-tidy/android/CloexecFopenCheck.h b/clang-tools-extra/clang-tidy/android/CloexecFopenCheck.h
index 646b237a663e0..a018fc5deaddb 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecFopenCheck.h
+++ b/clang-tools-extra/clang-tidy/android/CloexecFopenCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_FOPEN_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_FOPEN_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECFOPENCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECFOPENCHECK_H
#include "CloexecCheck.h"
@@ -30,4 +30,4 @@ class CloexecFopenCheck : public CloexecCheck {
} // namespace clang::tidy::android
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_FOPEN_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECFOPENCHECK_H
diff --git a/clang-tools-extra/clang-tidy/android/CloexecInotifyInit1Check.h b/clang-tools-extra/clang-tidy/android/CloexecInotifyInit1Check.h
index 3960d05e2e1f0..c2e45332fd048 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecInotifyInit1Check.h
+++ b/clang-tools-extra/clang-tidy/android/CloexecInotifyInit1Check.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_INOTIFY_INIT1_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_INOTIFY_INIT1_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECINOTIFYINIT1CHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECINOTIFYINIT1CHECK_H
#include "CloexecCheck.h"
@@ -27,4 +27,4 @@ class CloexecInotifyInit1Check : public CloexecCheck {
} // namespace clang::tidy::android
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_INOTIFY_INIT1_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECINOTIFYINIT1CHECK_H
diff --git a/clang-tools-extra/clang-tidy/android/CloexecInotifyInitCheck.h b/clang-tools-extra/clang-tidy/android/CloexecInotifyInitCheck.h
index cb9e6820571bc..cd202c2ad97f8 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecInotifyInitCheck.h
+++ b/clang-tools-extra/clang-tidy/android/CloexecInotifyInitCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_INOTIFY_INIT_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_INOTIFY_INIT_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECINOTIFYINITCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECINOTIFYINITCHECK_H
#include "CloexecCheck.h"
@@ -27,4 +27,4 @@ class CloexecInotifyInitCheck : public CloexecCheck {
} // namespace clang::tidy::android
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_INOTIFY_INIT_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECINOTIFYINITCHECK_H
diff --git a/clang-tools-extra/clang-tidy/android/CloexecMemfdCreateCheck.h b/clang-tools-extra/clang-tidy/android/CloexecMemfdCreateCheck.h
index dd96ee968f3b4..1a77c7fcb196f 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecMemfdCreateCheck.h
+++ b/clang-tools-extra/clang-tidy/android/CloexecMemfdCreateCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_MEMFD_CREATE_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_MEMFD_CREATE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECMEMFDCREATECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECMEMFDCREATECHECK_H
#include "CloexecCheck.h"
@@ -27,4 +27,4 @@ class CloexecMemfdCreateCheck : public CloexecCheck {
} // namespace clang::tidy::android
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_MEMFD_CREATE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECMEMFDCREATECHECK_H
diff --git a/clang-tools-extra/clang-tidy/android/CloexecOpenCheck.cpp b/clang-tools-extra/clang-tidy/android/CloexecOpenCheck.cpp
index 8c24482c73251..9938027c53b0e 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecOpenCheck.cpp
+++ b/clang-tools-extra/clang-tidy/android/CloexecOpenCheck.cpp
@@ -30,7 +30,7 @@ void CloexecOpenCheck::registerMatchers(MatchFinder *Finder) {
void CloexecOpenCheck::check(const MatchFinder::MatchResult &Result) {
const auto *FD = Result.Nodes.getNodeAs(FuncDeclBindingStr);
assert(FD->param_size() > 1);
- int ArgPos = (FD->param_size() > 2) ? 2 : 1;
+ const int ArgPos = (FD->param_size() > 2) ? 2 : 1;
insertMacroFlag(Result, /*MacroFlag=*/"O_CLOEXEC", ArgPos);
}
diff --git a/clang-tools-extra/clang-tidy/android/CloexecOpenCheck.h b/clang-tools-extra/clang-tidy/android/CloexecOpenCheck.h
index d95fe21fb3e88..d30b456dcdc17 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecOpenCheck.h
+++ b/clang-tools-extra/clang-tidy/android/CloexecOpenCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_OPEN_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_OPEN_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECOPENCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECOPENCHECK_H
#include "CloexecCheck.h"
@@ -32,4 +32,4 @@ class CloexecOpenCheck : public CloexecCheck {
} // namespace clang::tidy::android
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_OPEN_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECOPENCHECK_H
diff --git a/clang-tools-extra/clang-tidy/android/CloexecPipe2Check.h b/clang-tools-extra/clang-tidy/android/CloexecPipe2Check.h
index 496bd6b6cbbc0..31653081ef98d 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecPipe2Check.h
+++ b/clang-tools-extra/clang-tidy/android/CloexecPipe2Check.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_PIPE2_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_PIPE2_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECPIPE2CHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECPIPE2CHECK_H
#include "CloexecCheck.h"
@@ -27,4 +27,4 @@ class CloexecPipe2Check : public CloexecCheck {
} // namespace clang::tidy::android
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_PIPE2_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECPIPE2CHECK_H
diff --git a/clang-tools-extra/clang-tidy/android/CloexecPipeCheck.cpp b/clang-tools-extra/clang-tidy/android/CloexecPipeCheck.cpp
index a475dff4a2682..37e3c56e97021 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecPipeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/android/CloexecPipeCheck.cpp
@@ -20,7 +20,7 @@ void CloexecPipeCheck::registerMatchers(MatchFinder *Finder) {
}
void CloexecPipeCheck::check(const MatchFinder::MatchResult &Result) {
- std::string ReplacementText =
+ const std::string ReplacementText =
(Twine("pipe2(") + getSpellingArg(Result, 0) + ", O_CLOEXEC)").str();
replaceFunc(Result,
diff --git a/clang-tools-extra/clang-tidy/android/CloexecPipeCheck.h b/clang-tools-extra/clang-tidy/android/CloexecPipeCheck.h
index f0145e14eb49f..721a68883dd01 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecPipeCheck.h
+++ b/clang-tools-extra/clang-tidy/android/CloexecPipeCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_PIPE_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_PIPE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECPIPECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECPIPECHECK_H
#include "CloexecCheck.h"
@@ -27,4 +27,4 @@ class CloexecPipeCheck : public CloexecCheck {
} // namespace clang::tidy::android
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_PIPE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECPIPECHECK_H
diff --git a/clang-tools-extra/clang-tidy/android/CloexecSocketCheck.h b/clang-tools-extra/clang-tidy/android/CloexecSocketCheck.h
index 0a29d7224e781..8865db3a16788 100644
--- a/clang-tools-extra/clang-tidy/android/CloexecSocketCheck.h
+++ b/clang-tools-extra/clang-tidy/android/CloexecSocketCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_SOCKET_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_SOCKET_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECSOCKETCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECSOCKETCHECK_H
#include "CloexecCheck.h"
@@ -27,4 +27,4 @@ class CloexecSocketCheck : public CloexecCheck {
} // namespace clang::tidy::android
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_SOCKET_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXECSOCKETCHECK_H
diff --git a/clang-tools-extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.cpp b/clang-tools-extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.cpp
index 36ac9a44695c9..c42f069b487c3 100644
--- a/clang-tools-extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.cpp
+++ b/clang-tools-extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.cpp
@@ -64,7 +64,7 @@ void ComparisonInTempFailureRetryCheck::check(
const LangOptions &Opts = Result.Context->getLangOpts();
SourceLocation LocStart = Node.getBeginLoc();
while (LocStart.isMacroID()) {
- SourceLocation Invocation = SM.getImmediateMacroCallerLoc(LocStart);
+ const SourceLocation Invocation = SM.getImmediateMacroCallerLoc(LocStart);
Token Tok;
if (!Lexer::getRawToken(SM.getSpellingLoc(Invocation), Tok, SM, Opts,
/*IgnoreWhiteSpace=*/true)) {
diff --git a/clang-tools-extra/clang-tidy/boost/UseRangesCheck.cpp b/clang-tools-extra/clang-tidy/boost/UseRangesCheck.cpp
index 34ecee5badb15..36dd3c94ee19f 100644
--- a/clang-tools-extra/clang-tidy/boost/UseRangesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/boost/UseRangesCheck.cpp
@@ -18,6 +18,7 @@
#include
#include
#include
+#include
// FixItHint - Let the docs script know that this class does provide fixits
@@ -217,11 +218,11 @@ utils::UseRangesCheck::ReplacerMap UseRangesCheck::getReplacerMap() const {
const auto AddFromStd =
[&](llvm::IntrusiveRefCntPtr Replacer,
std::initializer_list Names) {
- AddFrom(Replacer, Names, "std");
+ AddFrom(std::move(Replacer), Names, "std");
};
const auto AddFromBoost =
- [&](llvm::IntrusiveRefCntPtr Replacer,
+ [&](const llvm::IntrusiveRefCntPtr &Replacer,
std::initializer_list<
std::pair>>
NamespaceAndNames) {
@@ -341,7 +342,7 @@ void UseRangesCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
}
DiagnosticBuilder UseRangesCheck::createDiag(const CallExpr &Call) {
- DiagnosticBuilder D =
+ const DiagnosticBuilder D =
diag(Call.getBeginLoc(), "use a %0 version of this algorithm");
D << (Call.getDirectCallee()->isInStdNamespace() ? "boost" : "ranged");
return D;
diff --git a/clang-tools-extra/clang-tidy/boost/UseToStringCheck.h b/clang-tools-extra/clang-tidy/boost/UseToStringCheck.h
index af87f15a1dc0b..dae3f7c125db4 100644
--- a/clang-tools-extra/clang-tidy/boost/UseToStringCheck.h
+++ b/clang-tools-extra/clang-tidy/boost/UseToStringCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BOOST_USE_TO_STRING_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BOOST_USE_TO_STRING_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BOOST_USETOSTRINGCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BOOST_USETOSTRINGCHECK_H
#include "../ClangTidyCheck.h"
@@ -32,4 +32,4 @@ class UseToStringCheck : public ClangTidyCheck {
} // namespace clang::tidy::boost
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BOOST_USE_TO_STRING_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BOOST_USETOSTRINGCHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
index c0a778a027377..ed30d01e645d1 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
@@ -81,14 +81,16 @@ static std::vector>
getCommentsInRange(ASTContext *Ctx, CharSourceRange Range) {
std::vector> Comments;
auto &SM = Ctx->getSourceManager();
- std::pair BeginLoc = SM.getDecomposedLoc(Range.getBegin()),
- EndLoc = SM.getDecomposedLoc(Range.getEnd());
+ const std::pair BeginLoc =
+ SM.getDecomposedLoc(Range.getBegin()),
+ EndLoc =
+ SM.getDecomposedLoc(Range.getEnd());
if (BeginLoc.first != EndLoc.first)
return Comments;
bool Invalid = false;
- StringRef Buffer = SM.getBufferData(BeginLoc.first, &Invalid);
+ const StringRef Buffer = SM.getBufferData(BeginLoc.first, &Invalid);
if (Invalid)
return Comments;
@@ -106,7 +108,7 @@ getCommentsInRange(ASTContext *Ctx, CharSourceRange Range) {
break;
if (Tok.is(tok::comment)) {
- std::pair CommentLoc =
+ const std::pair CommentLoc =
SM.getDecomposedLoc(Tok.getLocation());
assert(CommentLoc.first == BeginLoc.first);
Comments.emplace_back(
@@ -125,7 +127,7 @@ static std::vector>
getCommentsBeforeLoc(ASTContext *Ctx, SourceLocation Loc) {
std::vector> Comments;
while (Loc.isValid()) {
- clang::Token Tok = utils::lexer::getPreviousToken(
+ const clang::Token Tok = utils::lexer::getPreviousToken(
Loc, Ctx->getSourceManager(), Ctx->getLangOpts(),
/*SkipComments=*/false);
if (Tok.isNot(tok::comment))
@@ -142,11 +144,11 @@ getCommentsBeforeLoc(ASTContext *Ctx, SourceLocation Loc) {
static bool isLikelyTypo(llvm::ArrayRef Params,
StringRef ArgName, unsigned ArgIndex) {
- std::string ArgNameLowerStr = ArgName.lower();
- StringRef ArgNameLower = ArgNameLowerStr;
+ const std::string ArgNameLowerStr = ArgName.lower();
+ const StringRef ArgNameLower = ArgNameLowerStr;
// The threshold is arbitrary.
- unsigned UpperBound = ((ArgName.size() + 2) / 3) + 1;
- unsigned ThisED = ArgNameLower.edit_distance(
+ const unsigned UpperBound = ((ArgName.size() + 2) / 3) + 1;
+ const unsigned ThisED = ArgNameLower.edit_distance(
Params[ArgIndex]->getIdentifier()->getName().lower(),
/*AllowReplacements=*/true, UpperBound);
if (ThisED >= UpperBound)
@@ -155,7 +157,7 @@ static bool isLikelyTypo(llvm::ArrayRef Params,
for (unsigned I = 0, E = Params.size(); I != E; ++I) {
if (I == ArgIndex)
continue;
- IdentifierInfo *II = Params[I]->getIdentifier();
+ const IdentifierInfo *II = Params[I]->getIdentifier();
if (!II)
continue;
@@ -163,9 +165,9 @@ static bool isLikelyTypo(llvm::ArrayRef Params,
// Other parameters must be an edit distance at least Threshold more away
// from this parameter. This gives us greater confidence that this is a
// typo of this parameter and not one with a similar name.
- unsigned OtherED = ArgNameLower.edit_distance(II->getName().lower(),
- /*AllowReplacements=*/true,
- ThisED + Threshold);
+ const unsigned OtherED = ArgNameLower.edit_distance(
+ II->getName().lower(),
+ /*AllowReplacements=*/true, ThisED + Threshold);
if (OtherED < ThisED + Threshold)
return false;
}
@@ -267,7 +269,8 @@ void ArgumentCommentCheck::checkCallArgs(ASTContext *Ctx,
return;
Callee = Callee->getFirstDecl();
- unsigned NumArgs = std::min(Args.size(), Callee->getNumParams());
+ const unsigned NumArgs =
+ std::min(Args.size(), Callee->getNumParams());
if ((NumArgs == 0) || (IgnoreSingleArgument && NumArgs == 1))
return;
@@ -279,7 +282,7 @@ void ArgumentCommentCheck::checkCallArgs(ASTContext *Ctx,
for (unsigned I = 0; I < NumArgs; ++I) {
const ParmVarDecl *PVD = Callee->getParamDecl(I);
- IdentifierInfo *II = PVD->getIdentifier();
+ const IdentifierInfo *II = PVD->getIdentifier();
if (!II)
continue;
if (FunctionDecl *Template = Callee->getTemplateInstantiationPattern()) {
@@ -293,7 +296,7 @@ void ArgumentCommentCheck::checkCallArgs(ASTContext *Ctx,
}
}
- CharSourceRange BeforeArgument =
+ const CharSourceRange BeforeArgument =
MakeFileCharRange(ArgBeginLoc, Args[I]->getBeginLoc());
ArgBeginLoc = Args[I]->getEndLoc();
@@ -302,7 +305,7 @@ void ArgumentCommentCheck::checkCallArgs(ASTContext *Ctx,
Comments = getCommentsInRange(Ctx, BeforeArgument);
} else {
// Fall back to parsing back from the start of the argument.
- CharSourceRange ArgsRange =
+ const CharSourceRange ArgsRange =
MakeFileCharRange(Args[I]->getBeginLoc(), Args[I]->getEndLoc());
Comments = getCommentsBeforeLoc(Ctx, ArgsRange.getBegin());
}
@@ -312,7 +315,7 @@ void ArgumentCommentCheck::checkCallArgs(ASTContext *Ctx,
if (IdentRE.match(Comment.second, &Matches) &&
!sameName(Matches[2], II->getName(), StrictMode)) {
{
- DiagnosticBuilder Diag =
+ const DiagnosticBuilder Diag =
diag(Comment.first, "argument name '%0' in comment does not "
"match parameter name %1")
<< Matches[2] << II;
@@ -332,9 +335,9 @@ void ArgumentCommentCheck::checkCallArgs(ASTContext *Ctx,
// If the argument comments are missing for literals add them.
if (Comments.empty() && shouldAddComment(Args[I])) {
- std::string ArgComment =
+ const std::string ArgComment =
(llvm::Twine("/*") + II->getName() + "=*/").str();
- DiagnosticBuilder Diag =
+ const DiagnosticBuilder Diag =
diag(Args[I]->getBeginLoc(),
"argument comment missing for literal argument %0")
<< II
diff --git a/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
index 170050247014a..a29aa552b0953 100644
--- a/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
@@ -29,7 +29,7 @@ AST_MATCHER_P2(Expr, hasSideEffect, bool, CheckFunctionCalls,
const Expr *E = &Node;
if (const auto *Op = dyn_cast(E)) {
- UnaryOperator::Opcode OC = Op->getOpcode();
+ const UnaryOperator::Opcode OC = Op->getOpcode();
return OC == UO_PostInc || OC == UO_PostDec || OC == UO_PreInc ||
OC == UO_PreDec;
}
@@ -44,7 +44,7 @@ AST_MATCHER_P2(Expr, hasSideEffect, bool, CheckFunctionCalls,
if (MethodDecl->isConst())
return false;
- OverloadedOperatorKind OpKind = OpCallExpr->getOperator();
+ const OverloadedOperatorKind OpKind = OpCallExpr->getOperator();
return OpKind == OO_Equal || OpKind == OO_PlusEqual ||
OpKind == OO_MinusEqual || OpKind == OO_StarEqual ||
OpKind == OO_SlashEqual || OpKind == OO_AmpEqual ||
@@ -130,7 +130,7 @@ void AssertSideEffectCheck::check(const MatchFinder::MatchResult &Result) {
StringRef AssertMacroName;
while (Loc.isValid() && Loc.isMacroID()) {
- StringRef MacroName = Lexer::getImmediateMacroName(Loc, SM, LangOpts);
+ const StringRef MacroName = Lexer::getImmediateMacroName(Loc, SM, LangOpts);
Loc = SM.getImmediateMacroCallerLoc(Loc);
// Check if this macro is an assert.
diff --git a/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
index 2c8856298e7be..d5d8a29d96969 100644
--- a/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
@@ -66,7 +66,7 @@ void AssignmentInIfConditionCheck::check(
}
void AssignmentInIfConditionCheck::report(const Expr *AssignmentExpr) {
- SourceLocation OpLoc =
+ const SourceLocation OpLoc =
isa(AssignmentExpr)
? cast(AssignmentExpr)->getOperatorLoc()
: cast(AssignmentExpr)->getOperatorLoc();
diff --git a/clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp
index e1d0538ab1644..3e1188d5e2463 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp
@@ -40,7 +40,7 @@ void BadSignalToKillThreadCheck::check(const MatchFinder::MatchResult &Result) {
const Token &T = MI->tokens().back();
if (!T.isLiteral() || !T.getLiteralData())
return std::nullopt;
- StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength());
+ const StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength());
llvm::APInt IntValue;
constexpr unsigned AutoSenseRadix = 0;
diff --git a/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
index 07bb08166a006..8e0f0c55bdf94 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
@@ -281,8 +281,8 @@ static bool isIdenticalStmt(const ASTContext &Ctx, const Stmt *Stmt1,
const auto *IntLit1 = cast(Stmt1);
const auto *IntLit2 = cast(Stmt2);
- llvm::APInt I1 = IntLit1->getValue();
- llvm::APInt I2 = IntLit2->getValue();
+ const llvm::APInt I1 = IntLit1->getValue();
+ const llvm::APInt I2 = IntLit2->getValue();
if (I1.getBitWidth() != I2.getBitWidth())
return false;
return I1 == I2;
@@ -352,7 +352,7 @@ void BranchCloneCheck::check(const MatchFinder::MatchResult &Result) {
}
}
- size_t N = Branches.size();
+ const size_t N = Branches.size();
llvm::BitVector KnownAsClone(N);
for (size_t I = 0; I + 1 < N; I++) {
@@ -375,7 +375,7 @@ void BranchCloneCheck::check(const MatchFinder::MatchResult &Result) {
// We report the first occurrence only when we find the second one.
diag(Branches[I]->getBeginLoc(),
"repeated branch body in conditional chain");
- SourceLocation End =
+ const SourceLocation End =
Lexer::getLocForEndOfToken(Branches[I]->getEndLoc(), 0,
*Result.SourceManager, getLangOpts());
if (End.isValid()) {
diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index e6115f67656bc..3ba1532334e4a 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -22,13 +22,17 @@
#include "CommandProcessorCheck.h"
#include "ComparePointerToMemberVirtualFunctionCheck.h"
#include "CopyConstructorInitCheck.h"
+#include "CopyConstructorMutatesArgumentCheck.h"
#include "CrtpConstructorAccessibilityCheck.h"
#include "DanglingHandleCheck.h"
+#include "DefaultOperatorNewOnOveralignedTypeCheck.h"
#include "DerivedMethodShadowingBaseMethodCheck.h"
#include "DynamicStaticInitializersCheck.h"
#include "EasilySwappableParametersCheck.h"
#include "EmptyCatchCheck.h"
+#include "ExceptionCopyConstructorThrowsCheck.h"
#include "ExceptionEscapeCheck.h"
+#include "FloatLoopCounterCheck.h"
#include "FoldInitTypeCheck.h"
#include "ForwardDeclarationNamespaceCheck.h"
#include "ForwardingReferenceOverloadCheck.h"
@@ -61,6 +65,7 @@
#include "ParentVirtualCallCheck.h"
#include "PointerArithmeticOnPolymorphicObjectCheck.h"
#include "PosixReturnCheck.h"
+#include "RawMemoryCallOnNonTrivialTypeCheck.h"
#include "RedundantBranchConditionCheck.h"
#include "ReservedIdentifierCheck.h"
#include "ReturnConstRefFromParameterCheck.h"
@@ -71,6 +76,7 @@
#include "SizeofExpressionCheck.h"
#include "SpuriouslyWakeUpFunctionsCheck.h"
#include "StandaloneEmptyCheck.h"
+#include "StdNamespaceModificationCheck.h"
#include "StringConstructorCheck.h"
#include "StringIntegerAssignmentCheck.h"
#include "StringLiteralWithEmbeddedNulCheck.h"
@@ -137,8 +143,12 @@ class BugproneModule : public ClangTidyModule {
"bugprone-compare-pointer-to-member-virtual-function");
CheckFactories.registerCheck(
"bugprone-copy-constructor-init");
+ CheckFactories.registerCheck(
+ "bugprone-copy-constructor-mutates-argument");
CheckFactories.registerCheck(
"bugprone-dangling-handle");
+ CheckFactories.registerCheck(
+ "bugprone-default-operator-new-on-overaligned-type");
CheckFactories.registerCheck(
"bugprone-derived-method-shadowing-base-method");
CheckFactories.registerCheck(
@@ -146,8 +156,12 @@ class BugproneModule : public ClangTidyModule {
CheckFactories.registerCheck(
"bugprone-easily-swappable-parameters");
CheckFactories.registerCheck("bugprone-empty-catch");
+ CheckFactories.registerCheck(
+ "bugprone-exception-copy-constructor-throws");
CheckFactories.registerCheck(
"bugprone-exception-escape");
+ CheckFactories.registerCheck(
+ "bugprone-float-loop-counter");
CheckFactories.registerCheck("bugprone-fold-init-type");
CheckFactories.registerCheck(
"bugprone-forward-declaration-namespace");
@@ -216,6 +230,8 @@ class BugproneModule : public ClangTidyModule {
CheckFactories.registerCheck(
"bugprone-parent-virtual-call");
CheckFactories.registerCheck("bugprone-posix-return");
+ CheckFactories.registerCheck(
+ "bugprone-raw-memory-call-on-non-trivial-type");
CheckFactories.registerCheck(
"bugprone-reserved-identifier");
CheckFactories.registerCheck(
@@ -231,6 +247,8 @@ class BugproneModule : public ClangTidyModule {
"bugprone-spuriously-wake-up-functions");
CheckFactories.registerCheck(
"bugprone-standalone-empty");
+ CheckFactories.registerCheck(
+ "bugprone-std-namespace-modification");
CheckFactories.registerCheck(
"bugprone-string-constructor");
CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index c8943e5b22ef8..49c467aa5090c 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -18,13 +18,17 @@ add_clang_library(clangTidyBugproneModule STATIC
CommandProcessorCheck.cpp
ComparePointerToMemberVirtualFunctionCheck.cpp
CopyConstructorInitCheck.cpp
+ CopyConstructorMutatesArgumentCheck.cpp
CrtpConstructorAccessibilityCheck.cpp
DanglingHandleCheck.cpp
+ DefaultOperatorNewOnOveralignedTypeCheck.cpp
DerivedMethodShadowingBaseMethodCheck.cpp
DynamicStaticInitializersCheck.cpp
EasilySwappableParametersCheck.cpp
EmptyCatchCheck.cpp
+ ExceptionCopyConstructorThrowsCheck.cpp
ExceptionEscapeCheck.cpp
+ FloatLoopCounterCheck.cpp
FoldInitTypeCheck.cpp
ForwardDeclarationNamespaceCheck.cpp
ForwardingReferenceOverloadCheck.cpp
@@ -62,6 +66,7 @@ add_clang_library(clangTidyBugproneModule STATIC
ParentVirtualCallCheck.cpp
PointerArithmeticOnPolymorphicObjectCheck.cpp
PosixReturnCheck.cpp
+ RawMemoryCallOnNonTrivialTypeCheck.cpp
RedundantBranchConditionCheck.cpp
ReservedIdentifierCheck.cpp
ReturnConstRefFromParameterCheck.cpp
@@ -73,6 +78,7 @@ add_clang_library(clangTidyBugproneModule STATIC
SmartPtrArrayMismatchCheck.cpp
SpuriouslyWakeUpFunctionsCheck.cpp
StandaloneEmptyCheck.cpp
+ StdNamespaceModificationCheck.cpp
StringConstructorCheck.cpp
StringIntegerAssignmentCheck.cpp
StringLiteralWithEmbeddedNulCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/bugprone/CopyConstructorInitCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/CopyConstructorInitCheck.cpp
index 76bcbbbcdf680..ccbc86ae74cc6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CopyConstructorInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/CopyConstructorInitCheck.cpp
@@ -31,7 +31,7 @@ void CopyConstructorInitCheck::registerMatchers(MatchFinder *Finder) {
void CopyConstructorInitCheck::check(const MatchFinder::MatchResult &Result) {
const auto *Ctor = Result.Nodes.getNodeAs("ctor");
- std::string ParamName = Ctor->getParamDecl(0)->getNameAsString();
+ const std::string ParamName = Ctor->getParamDecl(0)->getNameAsString();
// We want only one warning (and FixIt) for each ctor.
std::string FixItInitList;
@@ -40,7 +40,7 @@ void CopyConstructorInitCheck::check(const MatchFinder::MatchResult &Result) {
bool HasWrittenInitializer = false;
SmallVector SafeFixIts;
for (const auto *Init : Ctor->inits()) {
- bool CtorInitIsWritten = Init->isWritten();
+ const bool CtorInitIsWritten = Init->isWritten();
HasWrittenInitializer = HasWrittenInitializer || CtorInitIsWritten;
if (!Init->isBaseInitializer())
continue;
diff --git a/clang-tools-extra/clang-tidy/bugprone/CopyConstructorInitCheck.h b/clang-tools-extra/clang-tidy/bugprone/CopyConstructorInitCheck.h
index cba1a25d9bc19..e977bc2466dc8 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CopyConstructorInitCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/CopyConstructorInitCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_COPY_CONSTRUCTOR_INIT_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_COPY_CONSTRUCTOR_INIT_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_COPYCONSTRUCTORINITCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_COPYCONSTRUCTORINITCHECK_H
#include "../ClangTidyCheck.h"
@@ -31,4 +31,4 @@ class CopyConstructorInitCheck : public ClangTidyCheck {
} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_COPY_CONSTRUCTOR_INIT_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_COPYCONSTRUCTORINITCHECK_H
diff --git a/clang-tools-extra/clang-tidy/cert/MutatingCopyCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/CopyConstructorMutatesArgumentCheck.cpp
similarity index 89%
rename from clang-tools-extra/clang-tidy/cert/MutatingCopyCheck.cpp
rename to clang-tools-extra/clang-tidy/bugprone/CopyConstructorMutatesArgumentCheck.cpp
index fb9d72ce6bd31..cbbb1a0070a02 100644
--- a/clang-tools-extra/clang-tidy/cert/MutatingCopyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/CopyConstructorMutatesArgumentCheck.cpp
@@ -6,19 +6,20 @@
//
//===----------------------------------------------------------------------===//
-#include "MutatingCopyCheck.h"
+#include "CopyConstructorMutatesArgumentCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
using namespace clang::ast_matchers;
-namespace clang::tidy::cert {
+namespace clang::tidy::bugprone {
static constexpr llvm::StringLiteral SourceDeclName = "ChangedPVD";
static constexpr llvm::StringLiteral MutatingOperatorName = "MutatingOp";
static constexpr llvm::StringLiteral MutatingCallName = "MutatingCall";
-void MutatingCopyCheck::registerMatchers(MatchFinder *Finder) {
+void CopyConstructorMutatesArgumentCheck::registerMatchers(
+ MatchFinder *Finder) {
const auto MemberExprOrSourceObject = anyOf(
memberExpr(),
declRefExpr(to(decl(equalsBoundNode(std::string(SourceDeclName))))));
@@ -60,7 +61,8 @@ void MutatingCopyCheck::registerMatchers(MatchFinder *Finder) {
this);
}
-void MutatingCopyCheck::check(const MatchFinder::MatchResult &Result) {
+void CopyConstructorMutatesArgumentCheck::check(
+ const MatchFinder::MatchResult &Result) {
if (const auto *MemberCall =
Result.Nodes.getNodeAs(MutatingCallName))
diag(MemberCall->getBeginLoc(), "call mutates copied object");
@@ -69,4 +71,4 @@ void MutatingCopyCheck::check(const MatchFinder::MatchResult &Result) {
diag(Assignment->getBeginLoc(), "mutating copied object");
}
-} // namespace clang::tidy::cert
+} // namespace clang::tidy::bugprone
diff --git a/clang-tools-extra/clang-tidy/cert/MutatingCopyCheck.h b/clang-tools-extra/clang-tidy/bugprone/CopyConstructorMutatesArgumentCheck.h
similarity index 60%
rename from clang-tools-extra/clang-tidy/cert/MutatingCopyCheck.h
rename to clang-tools-extra/clang-tidy/bugprone/CopyConstructorMutatesArgumentCheck.h
index c211fa004120c..0fed57258b0d8 100644
--- a/clang-tools-extra/clang-tidy/cert/MutatingCopyCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/CopyConstructorMutatesArgumentCheck.h
@@ -6,21 +6,21 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_MUTATINGCOPYCHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_MUTATINGCOPYCHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_COPYCONSTRUCTORMUTATESARGUMENTCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_COPYCONSTRUCTORMUTATESARGUMENTCHECK_H
#include "../ClangTidyCheck.h"
-namespace clang::tidy::cert {
+namespace clang::tidy::bugprone {
/// Finds assignments to the copied object and its direct or indirect members
/// in copy constructors and copy assignment operators.
///
/// For the user-facing documentation see:
-/// https://clang.llvm.org/extra/clang-tidy/checks/cert/oop58-cpp.html
-class MutatingCopyCheck : public ClangTidyCheck {
+/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/copy-constructor-mutates-argument.html
+class CopyConstructorMutatesArgumentCheck : public ClangTidyCheck {
public:
- MutatingCopyCheck(StringRef Name, ClangTidyContext *Context)
+ CopyConstructorMutatesArgumentCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
@@ -29,6 +29,6 @@ class MutatingCopyCheck : public ClangTidyCheck {
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};
-} // namespace clang::tidy::cert
+} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_MUTATINGCOPYCHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_COPYCONSTRUCTORMUTATESARGUMENTCHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/CrtpConstructorAccessibilityCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/CrtpConstructorAccessibilityCheck.cpp
index 60f7be8996933..5ef72eac763e7 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CrtpConstructorAccessibilityCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/CrtpConstructorAccessibilityCheck.cpp
@@ -116,9 +116,10 @@ void CrtpConstructorAccessibilityCheck::check(
assert(DerivedTemplateParameter &&
"No template parameter corresponds to the derived class of the CRTP.");
- bool NeedsFriend = !isDerivedParameterBefriended(CRTPDeclaration,
- DerivedTemplateParameter) &&
- !isDerivedClassBefriended(CRTPDeclaration, DerivedRecord);
+ const bool NeedsFriend =
+ !isDerivedParameterBefriended(CRTPDeclaration,
+ DerivedTemplateParameter) &&
+ !isDerivedClassBefriended(CRTPDeclaration, DerivedRecord);
const FixItHint HintFriend = FixItHint::CreateInsertion(
CRTPDeclaration->getBraceRange().getEnd(),
diff --git a/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.h b/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.h
index 486562c30f79e..0b71bc43057d9 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/DanglingHandleCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DANGLING_HANDLE_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DANGLING_HANDLE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DANGLINGHANDLECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DANGLINGHANDLECHECK_H
#include "../ClangTidyCheck.h"
@@ -37,4 +37,4 @@ class DanglingHandleCheck : public ClangTidyCheck {
} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DANGLING_HANDLE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DANGLINGHANDLECHECK_H
diff --git a/clang-tools-extra/clang-tidy/cert/DefaultOperatorNewAlignmentCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/DefaultOperatorNewOnOveralignedTypeCheck.cpp
similarity index 71%
rename from clang-tools-extra/clang-tidy/cert/DefaultOperatorNewAlignmentCheck.cpp
rename to clang-tools-extra/clang-tidy/bugprone/DefaultOperatorNewOnOveralignedTypeCheck.cpp
index 45c170ec20f4e..cb4f69ae96115 100644
--- a/clang-tools-extra/clang-tidy/cert/DefaultOperatorNewAlignmentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/DefaultOperatorNewOnOveralignedTypeCheck.cpp
@@ -6,26 +6,27 @@
//
//===----------------------------------------------------------------------===//
-#include "DefaultOperatorNewAlignmentCheck.h"
+#include "DefaultOperatorNewOnOveralignedTypeCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Basic/TargetInfo.h"
using namespace clang::ast_matchers;
-namespace clang::tidy::cert {
+namespace clang::tidy::bugprone {
-void DefaultOperatorNewAlignmentCheck::registerMatchers(MatchFinder *Finder) {
+void DefaultOperatorNewOnOveralignedTypeCheck::registerMatchers(
+ MatchFinder *Finder) {
Finder->addMatcher(
cxxNewExpr(unless(hasAnyPlacementArg(anything()))).bind("new"), this);
}
-void DefaultOperatorNewAlignmentCheck::check(
+void DefaultOperatorNewOnOveralignedTypeCheck::check(
const MatchFinder::MatchResult &Result) {
// Get the found 'new' expression.
const auto *NewExpr = Result.Nodes.getNodeAs("new");
- QualType T = NewExpr->getAllocatedType();
+ const QualType T = NewExpr->getAllocatedType();
// Dependent types do not have fixed alignment.
if (T->isDependentType())
return;
@@ -34,25 +35,25 @@ void DefaultOperatorNewAlignmentCheck::check(
if (!D || !D->isCompleteDefinition())
return;
- ASTContext &Context = D->getASTContext();
+ const ASTContext &Context = D->getASTContext();
// Check if no alignment was specified for the type.
if (!Context.isAlignmentRequired(T))
return;
// The user-specified alignment (in bits).
- unsigned SpecifiedAlignment = D->getMaxAlignment();
+ const unsigned SpecifiedAlignment = D->getMaxAlignment();
// Double-check if no alignment was specified.
if (!SpecifiedAlignment)
return;
// The alignment used by default 'operator new' (in bits).
- unsigned DefaultNewAlignment = Context.getTargetInfo().getNewAlign();
+ const unsigned DefaultNewAlignment = Context.getTargetInfo().getNewAlign();
- bool OverAligned = SpecifiedAlignment > DefaultNewAlignment;
- bool HasDefaultOperatorNew =
+ const bool OverAligned = SpecifiedAlignment > DefaultNewAlignment;
+ const bool HasDefaultOperatorNew =
!NewExpr->getOperatorNew() || NewExpr->getOperatorNew()->isImplicit();
- unsigned CharWidth = Context.getTargetInfo().getCharWidth();
+ const unsigned CharWidth = Context.getTargetInfo().getCharWidth();
if (HasDefaultOperatorNew && OverAligned)
diag(NewExpr->getBeginLoc(),
"allocation function returns a pointer with alignment %0 but the "
@@ -61,4 +62,4 @@ void DefaultOperatorNewAlignmentCheck::check(
<< (SpecifiedAlignment / CharWidth);
}
-} // namespace clang::tidy::cert
+} // namespace clang::tidy::bugprone
diff --git a/clang-tools-extra/clang-tidy/cert/DefaultOperatorNewAlignmentCheck.h b/clang-tools-extra/clang-tidy/bugprone/DefaultOperatorNewOnOveralignedTypeCheck.h
similarity index 56%
rename from clang-tools-extra/clang-tidy/cert/DefaultOperatorNewAlignmentCheck.h
rename to clang-tools-extra/clang-tidy/bugprone/DefaultOperatorNewOnOveralignedTypeCheck.h
index 8f9d0e470a755..b5b365b441209 100644
--- a/clang-tools-extra/clang-tidy/cert/DefaultOperatorNewAlignmentCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/DefaultOperatorNewOnOveralignedTypeCheck.h
@@ -6,21 +6,22 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_DEFAULTOPERATORNEWALIGNMENTCHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_DEFAULTOPERATORNEWALIGNMENTCHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DEFAULTOPERATORNEWONOVERALIGNEDTYPECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DEFAULTOPERATORNEWONOVERALIGNEDTYPECHECK_H
#include "../ClangTidyCheck.h"
-namespace clang::tidy::cert {
+namespace clang::tidy::bugprone {
/// Checks if an object of type with extended alignment is allocated by using
/// the default operator new.
///
/// For the user-facing documentation see:
-/// https://clang.llvm.org/extra/clang-tidy/checks/cert/mem57-cpp.html
-class DefaultOperatorNewAlignmentCheck : public ClangTidyCheck {
+/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/bugprone-default-operator-new-on-overaligned-type.html
+class DefaultOperatorNewOnOveralignedTypeCheck : public ClangTidyCheck {
public:
- DefaultOperatorNewAlignmentCheck(StringRef Name, ClangTidyContext *Context)
+ DefaultOperatorNewOnOveralignedTypeCheck(StringRef Name,
+ ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return !LangOpts.CPlusPlus17;
@@ -29,6 +30,6 @@ class DefaultOperatorNewAlignmentCheck : public ClangTidyCheck {
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};
-} // namespace clang::tidy::cert
+} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_DEFAULTOPERATORNEWALIGNMENTCHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DEFAULTOPERATORNEWONOVERALIGNEDTYPECHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp
index 743e6cd27509b..7c5867619cf4e 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp
@@ -65,7 +65,7 @@ AST_MATCHER(CXXMethodDecl, nameCollidesWithMethodInBase) {
for (const auto &BaseMethod : CurrentRecord->methods()) {
if (namesCollide(*BaseMethod, Node)) {
- ast_matchers::internal::BoundNodesTreeBuilder Result(*Builder);
+ const ast_matchers::internal::BoundNodesTreeBuilder Result(*Builder);
Builder->setBinding("base_method",
clang::DynTypedNode::create(*BaseMethod));
return true;
diff --git a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
index 4d0428ec18598..48de7fbe7fad6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
@@ -43,7 +43,7 @@ void DynamicStaticInitializersCheck::registerMatchers(MatchFinder *Finder) {
void DynamicStaticInitializersCheck::check(
const MatchFinder::MatchResult &Result) {
const auto *Var = Result.Nodes.getNodeAs("var");
- SourceLocation Loc = Var->getLocation();
+ const SourceLocation Loc = Var->getLocation();
if (!Loc.isValid() || !utils::isPresumedLocInHeaderFile(
Loc, *Result.SourceManager, HeaderFileExtensions))
return;
diff --git a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
index e02c62a53ffa0..00e4bb1e75000 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DYNAMIC_STATIC_INITIALIZERS_CHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DYNAMIC_STATIC_INITIALIZERS_CHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DYNAMICSTATICINITIALIZERSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DYNAMICSTATICINITIALIZERSCHECK_H
#include "../ClangTidyCheck.h"
#include "../FileExtensionsSet.h"
@@ -30,4 +30,4 @@ class DynamicStaticInitializersCheck : public ClangTidyCheck {
} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DYNAMIC_STATIC_INITIALIZERS_CHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DYNAMICSTATICINITIALIZERSCHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
index b4ee35154f5f0..a07a68c8a3e65 100644
--- a/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
@@ -417,7 +417,7 @@ struct MixData {
void sanitize() {
assert(Flags != MixFlags::Invalid && "sanitize() called on invalid bitvec");
- MixFlags CanonicalAndWorkaround =
+ const MixFlags CanonicalAndWorkaround =
MixFlags::Canonical | MixFlags::WorkaroundDisableCanonicalEquivalence;
if ((Flags & CanonicalAndWorkaround) == CanonicalAndWorkaround) {
// A workaround for too eagerly equivalent canonical types was requested,
@@ -483,7 +483,7 @@ struct MixData {
if (CommonType.isNull())
return *this;
- QualType NewCommonType = Func(CommonType);
+ const QualType NewCommonType = Func(CommonType);
if (CreatedFromOneWayConversion) {
MixData M{Flags, Conversion};
@@ -761,7 +761,7 @@ calculateMixability(const TheCheck &Check, QualType LType, QualType RType,
return {MixFlags::None};
}
- MixData UnqualifiedMixability =
+ const MixData UnqualifiedMixability =
calculateMixability(Check, LType.getLocalUnqualifiedType(),
RType.getLocalUnqualifiedType(), Ctx, ImplicitMode)
.withCommonTypeTransformed([&AdditionalQuals, &Ctx](QualType QT) {
@@ -813,7 +813,7 @@ calculateMixability(const TheCheck &Check, QualType LType, QualType RType,
if (ImplicitMode > ImplicitConversionModellingMode::None) {
LLVM_DEBUG(llvm::dbgs() << "--- calculateMixability. Start implicit...\n");
- MixData MixLTR =
+ const MixData MixLTR =
approximateImplicitConversion(Check, LType, RType, Ctx, ImplicitMode);
LLVM_DEBUG(
if (hasFlag(MixLTR.Flags, MixFlags::ImplicitConversion)) llvm::dbgs()
@@ -833,7 +833,7 @@ calculateMixability(const TheCheck &Check, QualType LType, QualType RType,
// Otherwise if the invoker requested a full modelling, do the other
// direction as well.
- MixData MixRTL =
+ const MixData MixRTL =
approximateImplicitConversion(Check, RType, LType, Ctx, ImplicitMode);
LLVM_DEBUG(
if (hasFlag(MixRTL.Flags, MixFlags::ImplicitConversion)) llvm::dbgs()
@@ -868,7 +868,7 @@ calculateMixability(const TheCheck &Check, QualType LType, QualType RType,
// If none of the previous logic found a match, try if Clang otherwise
// believes the types to be the same.
- QualType LCanonical = LType.getCanonicalType();
+ const QualType LCanonical = LType.getCanonicalType();
if (LCanonical == RType.getCanonicalType()) {
LLVM_DEBUG(llvm::dbgs()
<< "<<< calculateMixability. Same CanonicalType.\n");
@@ -983,9 +983,9 @@ approximateStandardConversionSequence(const TheCheck &Check, QualType From,
// Numeric promotions and conversions.
const auto *FromBuiltin = WorkType->getAs();
const auto *ToBuiltin = To->getAs();
- bool FromNumeric = FromBuiltin && (FromBuiltin->isIntegerType() ||
- FromBuiltin->isFloatingType());
- bool ToNumeric =
+ const bool FromNumeric = FromBuiltin && (FromBuiltin->isIntegerType() ||
+ FromBuiltin->isFloatingType());
+ const bool ToNumeric =
ToBuiltin && (ToBuiltin->isIntegerType() || ToBuiltin->isFloatingType());
if (FromNumeric && ToNumeric) {
// If both are integral types, the numeric conversion is performed.
@@ -1150,9 +1150,9 @@ class UserDefinedConversionSelector {
continue;
}
- bool BestConversionHasImplicit =
+ const bool BestConversionHasImplicit =
hasFlag(BestConversion->Flags, MixFlags::ImplicitConversion);
- bool ThisConversionHasImplicit =
+ const bool ThisConversionHasImplicit =
hasFlag(Prepared.Flags, MixFlags::ImplicitConversion);
if (!BestConversionHasImplicit && ThisConversionHasImplicit)
// This is a worse conversion, because a better one was found earlier.
@@ -1221,7 +1221,7 @@ tryConversionOperators(const TheCheck &Check, const CXXRecordDecl *RD,
if (std::optional
SelectedConversion = ConversionSet()) {
- CanQualType RecordType = RD->getASTContext().getCanonicalTagType(RD);
+ const CanQualType RecordType = RD->getASTContext().getCanonicalTagType(RD);
ConversionSequence Result{RecordType, ToType};
// The conversion from the operator call's return type to ToType was
@@ -1272,7 +1272,7 @@ tryConvertingConstructors(const TheCheck &Check, QualType FromType,
if (std::optional
SelectedConversion = ConversionSet()) {
- CanQualType RecordType = RD->getASTContext().getCanonicalTagType(RD);
+ const CanQualType RecordType = RD->getASTContext().getCanonicalTagType(RD);
ConversionSequence Result{FromType, RecordType};
Result.AfterFirstStandard = SelectedConversion->Seq.AfterFirstStandard;
@@ -1385,7 +1385,7 @@ approximateImplicitConversion(const TheCheck &Check, QualType LType,
LLVM_DEBUG(
llvm::dbgs()
<< "--- approximateImplicitConversion. Try to find post-conversion.\n");
- MixData SecondStdConv = approximateImplicitConversion(
+ const MixData SecondStdConv = approximateImplicitConversion(
Check, WorkType, RType, Ctx,
ImplicitConversionModellingMode::OneWaySingleStandardOnly);
if (SecondStdConv.indicatesMixability()) {
@@ -1414,7 +1414,7 @@ approximateImplicitConversion(const TheCheck &Check, QualType LType,
static MixableParameterRange modelMixingRange(
const TheCheck &Check, const FunctionDecl *FD, std::size_t StartIndex,
const filter::SimilarlyUsedParameterPairSuppressor &UsageBasedSuppressor) {
- std::size_t NumParams = FD->getNumParams();
+ const std::size_t NumParams = FD->getNumParams();
assert(StartIndex < NumParams && "out of bounds for start");
const ASTContext &Ctx = FD->getASTContext();
@@ -1424,7 +1424,7 @@ static MixableParameterRange modelMixingRange(
for (std::size_t I = StartIndex + 1; I < NumParams; ++I) {
const ParmVarDecl *Ith = FD->getParamDecl(I);
- StringRef ParamName = Ith->getName();
+ const StringRef ParamName = Ith->getName();
LLVM_DEBUG(llvm::dbgs()
<< "Check param #" << I << " '" << ParamName << "'...\n");
if (filter::isIgnoredParameter(Check, Ith)) {
@@ -1432,7 +1432,7 @@ static MixableParameterRange modelMixingRange(
break;
}
- StringRef PrevParamName = FD->getParamDecl(I - 1)->getName();
+ const StringRef PrevParamName = FD->getParamDecl(I - 1)->getName();
if (!ParamName.empty() && !PrevParamName.empty() &&
filter::prefixSuffixCoverUnderThreshold(
Check.NamePrefixSuffixSilenceDissimilarityThreshold, PrevParamName,
@@ -1518,18 +1518,18 @@ static bool isIgnoredParameter(const TheCheck &Check, const ParmVarDecl *Node) {
if (!Node->getIdentifier())
return llvm::is_contained(Check.IgnoredParameterNames, "\"\"");
- StringRef NodeName = Node->getName();
+ const StringRef NodeName = Node->getName();
if (llvm::is_contained(Check.IgnoredParameterNames, NodeName)) {
LLVM_DEBUG(llvm::dbgs() << "\tName ignored.\n");
return true;
}
- StringRef NodeTypeName = [Node] {
+ const StringRef NodeTypeName = [Node] {
const ASTContext &Ctx = Node->getASTContext();
const SourceManager &SM = Ctx.getSourceManager();
SourceLocation B = Node->getTypeSpecStartLoc();
SourceLocation E = Node->getTypeSpecEndLoc();
- LangOptions LO;
+ const LangOptions LO;
LLVM_DEBUG(llvm::dbgs() << "\tType name code is '"
<< Lexer::getSourceText(
@@ -1633,7 +1633,7 @@ class AppearsInSameExpr : public RecursiveASTVisitor {
RootSetInCurrentStackFrame = true;
}
- bool Ret = Base::TraverseStmt(S);
+ const bool Ret = Base::TraverseStmt(S);
if (RootSetInCurrentStackFrame)
CurrentExprOnlyTreeRoot = nullptr;
@@ -1684,7 +1684,7 @@ class PassedToSameFunction {
continue;
std::optional TargetIdx;
- unsigned NumFnParams = CalledFn->getNumParams();
+ const unsigned NumFnParams = CalledFn->getNumParams();
for (unsigned Idx = 0; Idx < NumFnParams; ++Idx)
if (CalledFn->getParamDecl(Idx) == PassedToParam)
TargetIdx.emplace(Idx);
@@ -1837,16 +1837,16 @@ static void padStringAtBegin(SmallVectorImpl &Str, std::size_t ToLen) {
static bool isCommonPrefixWithoutSomeCharacters(std::size_t N, StringRef S1,
StringRef S2) {
assert(S1.size() >= N && S2.size() >= N);
- StringRef S1Prefix = S1.take_front(S1.size() - N),
- S2Prefix = S2.take_front(S2.size() - N);
+ const StringRef S1Prefix = S1.take_front(S1.size() - N),
+ S2Prefix = S2.take_front(S2.size() - N);
return S1Prefix == S2Prefix && !S1Prefix.empty();
}
static bool isCommonSuffixWithoutSomeCharacters(std::size_t N, StringRef S1,
StringRef S2) {
assert(S1.size() >= N && S2.size() >= N);
- StringRef S1Suffix = S1.take_back(S1.size() - N),
- S2Suffix = S2.take_back(S2.size() - N);
+ const StringRef S1Suffix = S1.take_back(S1.size() - N),
+ S2Suffix = S2.take_back(S2.size() - N);
return S1Suffix == S2Suffix && !S1Suffix.empty();
}
@@ -1858,7 +1858,7 @@ static bool prefixSuffixCoverUnderThreshold(std::size_t Threshold,
return false;
// Pad the two strings to the longer length.
- std::size_t BiggerLength = std::max(Str1.size(), Str2.size());
+ const std::size_t BiggerLength = std::max(Str1.size(), Str2.size());
if (BiggerLength <= Threshold)
// If the length of the strings is still smaller than the threshold, they
@@ -1980,7 +1980,7 @@ struct FormattedConversionSequence {
// However, the parameter's defined type might not be what the implicit
// conversion started with, e.g. if a typedef is found to convert.
- std::string SeqBeginTypeStr = Conv.Begin.getAsString(PP);
+ const std::string SeqBeginTypeStr = Conv.Begin.getAsString(PP);
std::string SeqEndTypeStr = Conv.End.getAsString(PP);
if (StartTypeAsDiagnosed != SeqBeginTypeStr) {
OS << " (as '" << SeqBeginTypeStr << "')";
@@ -1995,7 +1995,7 @@ struct FormattedConversionSequence {
++NumElementsAdded;
}
};
- for (QualType InvolvedType : Conv.getInvolvedTypesInSequence())
+ for (const QualType InvolvedType : Conv.getInvolvedTypesInSequence())
// Print every type that's unique in the sequence into the diagnosis.
AddType(InvolvedType.getAsString(PP));
@@ -2073,12 +2073,14 @@ class UniqueTypeAliasDiagnosticHelper
if (CommonType.isNull() || CommonType == LHSType || CommonType == RHSType)
return Base::operator()({LHSType, RHSType, {}});
- TypeAliasDiagnosticTuple ThreeTuple{LHSType, RHSType, CommonType};
+ const TypeAliasDiagnosticTuple ThreeTuple{LHSType, RHSType, CommonType};
if (!Base::operator()(ThreeTuple))
return false;
- bool AlreadySaidLHSAndCommonIsSame = calledWith({LHSType, CommonType, {}});
- bool AlreadySaidRHSAndCommonIsSame = calledWith({RHSType, CommonType, {}});
+ const bool AlreadySaidLHSAndCommonIsSame =
+ calledWith({LHSType, CommonType, {}});
+ const bool AlreadySaidRHSAndCommonIsSame =
+ calledWith({RHSType, CommonType, {}});
if (AlreadySaidLHSAndCommonIsSame && AlreadySaidRHSAndCommonIsSame) {
// "SomeInt == int" && "SomeOtherInt == int" => "Common(SomeInt,
// SomeOtherInt) == int", no need to diagnose it. Save the 3-tuple only
@@ -2154,12 +2156,12 @@ void EasilySwappableParametersCheck::check(
assert(FD);
const PrintingPolicy &PP = FD->getASTContext().getPrintingPolicy();
- std::size_t NumParams = FD->getNumParams();
+ const std::size_t NumParams = FD->getNumParams();
std::size_t MixableRangeStartIndex = 0;
// Spawn one suppressor and if the user requested, gather information from
// the AST for the parameters' usages.
- filter::SimilarlyUsedParameterPairSuppressor UsageBasedSuppressor{
+ const filter::SimilarlyUsedParameterPairSuppressor UsageBasedSuppressor{
FD, SuppressParametersUsedTogether};
LLVM_DEBUG(llvm::dbgs() << "Begin analysis of " << getName(FD) << " with "
@@ -2182,11 +2184,13 @@ void EasilySwappableParametersCheck::check(
continue;
}
- bool NeedsAnyTypeNote = llvm::any_of(R.Mixes, needsToPrintTypeInDiagnostic);
- bool HasAnyImplicits =
+ const bool NeedsAnyTypeNote =
+ llvm::any_of(R.Mixes, needsToPrintTypeInDiagnostic);
+ const bool HasAnyImplicits =
llvm::any_of(R.Mixes, needsToElaborateImplicitConversion);
const ParmVarDecl *First = R.getFirstParam(), *Last = R.getLastParam();
- std::string FirstParamTypeAsWritten = First->getType().getAsString(PP);
+ const std::string FirstParamTypeAsWritten =
+ First->getType().getAsString(PP);
{
StringRef DiagText;
@@ -2205,7 +2209,7 @@ void EasilySwappableParametersCheck::check(
if (!NeedsAnyTypeNote)
Diag << FirstParamTypeAsWritten;
- CharSourceRange HighlightRange = CharSourceRange::getTokenRange(
+ const CharSourceRange HighlightRange = CharSourceRange::getTokenRange(
First->getBeginLoc(), Last->getEndLoc());
Diag << HighlightRange;
}
@@ -2240,12 +2244,12 @@ void EasilySwappableParametersCheck::check(
// emitted to a note diagnostic, so prepare it.
const ParmVarDecl *LVar = M.First;
const ParmVarDecl *RVar = M.Second;
- QualType LType = LVar->getType();
- QualType RType = RVar->getType();
- QualType CommonType = M.commonUnderlyingType();
- std::string LTypeStr = LType.getAsString(PP);
- std::string RTypeStr = RType.getAsString(PP);
- std::string CommonTypeStr = CommonType.getAsString(PP);
+ const QualType LType = LVar->getType();
+ const QualType RType = RVar->getType();
+ const QualType CommonType = M.commonUnderlyingType();
+ const std::string LTypeStr = LType.getAsString(PP);
+ const std::string RTypeStr = RType.getAsString(PP);
+ const std::string CommonTypeStr = CommonType.getAsString(PP);
if (hasFlag(M.flags(), MixFlags::TypeAlias) &&
UniqueTypeAlias(LType, RType, CommonType)) {
@@ -2274,8 +2278,9 @@ void EasilySwappableParametersCheck::check(
if ((hasFlag(M.flags(), MixFlags::ReferenceBind) ||
hasFlag(M.flags(), MixFlags::Qualifiers)) &&
UniqueBindPower({LType, RType})) {
- StringRef DiagText = "'%0' and '%1' parameters accept and bind the "
- "same kind of values";
+ const StringRef DiagText =
+ "'%0' and '%1' parameters accept and bind the "
+ "same kind of values";
diag(RVar->getOuterLocStart(), DiagText, DiagnosticIDs::Note)
<< LTypeStr << RTypeStr;
}
@@ -2286,8 +2291,8 @@ void EasilySwappableParametersCheck::check(
M.leftToRightConversionSequence();
const model::ConversionSequence &RTL =
M.rightToLeftConversionSequence();
- FormattedConversionSequence LTRFmt{PP, LTypeStr, LTR, RTypeStr};
- FormattedConversionSequence RTLFmt{PP, RTypeStr, RTL, LTypeStr};
+ const FormattedConversionSequence LTRFmt{PP, LTypeStr, LTR, RTypeStr};
+ const FormattedConversionSequence RTLFmt{PP, RTypeStr, RTL, LTypeStr};
StringRef DiagText = "'%0' and '%1' may be implicitly converted";
if (!LTRFmt.Trivial || !RTLFmt.Trivial)
@@ -2302,7 +2307,7 @@ void EasilySwappableParametersCheck::check(
Diag << LTRFmt.DiagnosticText << RTLFmt.DiagnosticText;
}
- StringRef ConversionFunctionDiagText =
+ const StringRef ConversionFunctionDiagText =
"the implicit conversion involves the "
"%select{|converting constructor|conversion operator}0 "
"declared here";
diff --git a/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
index eebab847d1070..5dd2f62504c71 100644
--- a/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
@@ -25,7 +25,7 @@ AST_MATCHER(CXXCatchStmt, isInMacro) {
}
AST_MATCHER_P(CXXCatchStmt, hasHandler, Matcher, InnerMatcher) {
- Stmt *Handler = Node.getHandlerBlock();
+ const Stmt *Handler = Node.getHandlerBlock();
if (!Handler)
return false;
return InnerMatcher.matches(*Handler, Finder, Builder);
@@ -41,7 +41,7 @@ AST_MATCHER_P(CompoundStmt, hasAnyTextFromList, std::vector,
return false;
ASTContext &Context = Finder->getASTContext();
- SourceManager &SM = Context.getSourceManager();
+ const SourceManager &SM = Context.getSourceManager();
StringRef Text = Lexer::getSourceText(
CharSourceRange::getTokenRange(Node.getSourceRange()), SM,
Context.getLangOpts());
diff --git a/clang-tools-extra/clang-tidy/cert/ThrownExceptionTypeCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ExceptionCopyConstructorThrowsCheck.cpp
similarity index 75%
rename from clang-tools-extra/clang-tidy/cert/ThrownExceptionTypeCheck.cpp
rename to clang-tools-extra/clang-tidy/bugprone/ExceptionCopyConstructorThrowsCheck.cpp
index 2225a90aeece1..73658459b8e26 100644
--- a/clang-tools-extra/clang-tidy/cert/ThrownExceptionTypeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ExceptionCopyConstructorThrowsCheck.cpp
@@ -6,15 +6,16 @@
//
//===----------------------------------------------------------------------===//
-#include "ThrownExceptionTypeCheck.h"
+#include "ExceptionCopyConstructorThrowsCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
using namespace clang::ast_matchers;
-namespace clang::tidy::cert {
+namespace clang::tidy::bugprone {
-void ThrownExceptionTypeCheck::registerMatchers(MatchFinder *Finder) {
+void ExceptionCopyConstructorThrowsCheck::registerMatchers(
+ MatchFinder *Finder) {
Finder->addMatcher(
traverse(
TK_AsIs,
@@ -25,10 +26,11 @@ void ThrownExceptionTypeCheck::registerMatchers(MatchFinder *Finder) {
this);
}
-void ThrownExceptionTypeCheck::check(const MatchFinder::MatchResult &Result) {
+void ExceptionCopyConstructorThrowsCheck::check(
+ const MatchFinder::MatchResult &Result) {
const auto *E = Result.Nodes.getNodeAs("expr");
diag(E->getExprLoc(),
"thrown exception type is not nothrow copy constructible");
}
-} // namespace clang::tidy::cert
+} // namespace clang::tidy::bugprone
diff --git a/clang-tools-extra/clang-tidy/cert/ThrownExceptionTypeCheck.h b/clang-tools-extra/clang-tidy/bugprone/ExceptionCopyConstructorThrowsCheck.h
similarity index 58%
rename from clang-tools-extra/clang-tidy/cert/ThrownExceptionTypeCheck.h
rename to clang-tools-extra/clang-tidy/bugprone/ExceptionCopyConstructorThrowsCheck.h
index 41a5145209686..f1d7cca0e5bad 100644
--- a/clang-tools-extra/clang-tidy/cert/ThrownExceptionTypeCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/ExceptionCopyConstructorThrowsCheck.h
@@ -6,20 +6,20 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_THROWNEXCEPTIONTYPECHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_THROWNEXCEPTIONTYPECHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTIONCOPYCONSTRUCTORTHROWSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTIONCOPYCONSTRUCTORTHROWSCHECK_H
#include "../ClangTidyCheck.h"
-namespace clang::tidy::cert {
+namespace clang::tidy::bugprone {
/// Checks whether a thrown object is nothrow copy constructible.
///
/// For the user-facing documentation see:
-/// https://clang.llvm.org/extra/clang-tidy/checks/cert/err60-cpp.html
-class ThrownExceptionTypeCheck : public ClangTidyCheck {
+/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/exception-copy-constructor-throws.html
+class ExceptionCopyConstructorThrowsCheck : public ClangTidyCheck {
public:
- ThrownExceptionTypeCheck(StringRef Name, ClangTidyContext *Context)
+ ExceptionCopyConstructorThrowsCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
@@ -28,6 +28,6 @@ class ThrownExceptionTypeCheck : public ClangTidyCheck {
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};
-} // namespace clang::tidy::cert
+} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_THROWNEXCEPTIONTYPECHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTIONCOPYCONSTRUCTORTHROWSCHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
index 837a86ff8655e..b7de8395ffa05 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
@@ -36,13 +36,22 @@ ExceptionEscapeCheck::ExceptionEscapeCheck(StringRef Name,
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context), RawFunctionsThatShouldNotThrow(Options.get(
"FunctionsThatShouldNotThrow", "")),
- RawIgnoredExceptions(Options.get("IgnoredExceptions", "")) {
+ RawIgnoredExceptions(Options.get("IgnoredExceptions", "")),
+ RawCheckedSwapFunctions(
+ Options.get("CheckedSwapFunctions", "swap,iter_swap,iter_move")),
+ CheckDestructors(Options.get("CheckDestructors", true)),
+ CheckMoveMemberFunctions(Options.get("CheckMoveMemberFunctions", true)),
+ CheckMain(Options.get("CheckMain", true)),
+ CheckNothrowFunctions(Options.get("CheckNothrowFunctions", true)) {
llvm::SmallVector FunctionsThatShouldNotThrowVec,
- IgnoredExceptionsVec;
+ IgnoredExceptionsVec, CheckedSwapFunctionsVec;
RawFunctionsThatShouldNotThrow.split(FunctionsThatShouldNotThrowVec, ",", -1,
false);
FunctionsThatShouldNotThrow.insert_range(FunctionsThatShouldNotThrowVec);
+ RawCheckedSwapFunctions.split(CheckedSwapFunctionsVec, ",", -1, false);
+ CheckedSwapFunctions.insert_range(CheckedSwapFunctionsVec);
+
llvm::StringSet<> IgnoredExceptions;
RawIgnoredExceptions.split(IgnoredExceptionsVec, ",", -1, false);
IgnoredExceptions.insert_range(IgnoredExceptionsVec);
@@ -54,20 +63,33 @@ void ExceptionEscapeCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "FunctionsThatShouldNotThrow",
RawFunctionsThatShouldNotThrow);
Options.store(Opts, "IgnoredExceptions", RawIgnoredExceptions);
+ Options.store(Opts, "CheckedSwapFunctions", RawCheckedSwapFunctions);
+ Options.store(Opts, "CheckDestructors", CheckDestructors);
+ Options.store(Opts, "CheckMoveMemberFunctions", CheckMoveMemberFunctions);
+ Options.store(Opts, "CheckMain", CheckMain);
+ Options.store(Opts, "CheckNothrowFunctions", CheckNothrowFunctions);
}
void ExceptionEscapeCheck::registerMatchers(MatchFinder *Finder) {
+ auto MatchIf = [](bool Enabled, const auto &Matcher) {
+ ast_matchers::internal::Matcher Nothing = unless(anything());
+ return Enabled ? Matcher : Nothing;
+ };
Finder->addMatcher(
functionDecl(
isDefinition(),
- anyOf(isNoThrow(),
- allOf(anyOf(cxxDestructorDecl(),
- cxxConstructorDecl(isMoveConstructor()),
- cxxMethodDecl(isMoveAssignmentOperator()), isMain(),
- allOf(hasAnyName("swap", "iter_swap", "iter_move"),
- hasAtLeastOneParameter())),
- unless(isExplicitThrow())),
- isEnabled(FunctionsThatShouldNotThrow)))
+ anyOf(
+ MatchIf(CheckNothrowFunctions, isNoThrow()),
+ allOf(anyOf(MatchIf(CheckDestructors, cxxDestructorDecl()),
+ MatchIf(
+ CheckMoveMemberFunctions,
+ anyOf(cxxConstructorDecl(isMoveConstructor()),
+ cxxMethodDecl(isMoveAssignmentOperator()))),
+ MatchIf(CheckMain, isMain()),
+ allOf(isEnabled(CheckedSwapFunctions),
+ hasAtLeastOneParameter())),
+ unless(isExplicitThrow())),
+ isEnabled(FunctionsThatShouldNotThrow)))
.bind("thrower"),
this);
}
diff --git a/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.h b/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.h
index bd1e7bae57f5d..c3bf4a4335273 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTION_ESCAPE_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTION_ESCAPE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTIONESCAPECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTIONESCAPECHECK_H
#include "../ClangTidyCheck.h"
#include "../utils/ExceptionAnalyzer.h"
@@ -35,11 +35,18 @@ class ExceptionEscapeCheck : public ClangTidyCheck {
private:
StringRef RawFunctionsThatShouldNotThrow;
StringRef RawIgnoredExceptions;
+ StringRef RawCheckedSwapFunctions;
+
+ const bool CheckDestructors;
+ const bool CheckMoveMemberFunctions;
+ const bool CheckMain;
+ const bool CheckNothrowFunctions;
llvm::StringSet<> FunctionsThatShouldNotThrow;
+ llvm::StringSet<> CheckedSwapFunctions;
utils::ExceptionAnalyzer Tracer;
};
} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTION_ESCAPE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTIONESCAPECHECK_H
diff --git a/clang-tools-extra/clang-tidy/cert/FloatLoopCounter.cpp b/clang-tools-extra/clang-tidy/bugprone/FloatLoopCounterCheck.cpp
similarity index 86%
rename from clang-tools-extra/clang-tidy/cert/FloatLoopCounter.cpp
rename to clang-tools-extra/clang-tidy/bugprone/FloatLoopCounterCheck.cpp
index 01299e0e5ab48..adf2d2b4bcc07 100644
--- a/clang-tools-extra/clang-tidy/cert/FloatLoopCounter.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/FloatLoopCounterCheck.cpp
@@ -6,16 +6,16 @@
//
//===----------------------------------------------------------------------===//
-#include "FloatLoopCounter.h"
+#include "FloatLoopCounterCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
using namespace clang::ast_matchers;
-namespace clang::tidy::cert {
+namespace clang::tidy::bugprone {
-void FloatLoopCounter::registerMatchers(MatchFinder *Finder) {
+void FloatLoopCounterCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
forStmt(hasIncrement(forEachDescendant(
declRefExpr(hasType(realFloatingPointType()),
@@ -29,7 +29,7 @@ void FloatLoopCounter::registerMatchers(MatchFinder *Finder) {
this);
}
-void FloatLoopCounter::check(const MatchFinder::MatchResult &Result) {
+void FloatLoopCounterCheck::check(const MatchFinder::MatchResult &Result) {
const auto *FS = Result.Nodes.getNodeAs("for");
diag(FS->getInc()->getBeginLoc(), "loop induction expression should not have "
@@ -43,4 +43,4 @@ void FloatLoopCounter::check(const MatchFinder::MatchResult &Result) {
DiagnosticIDs::Note);
}
-} // namespace clang::tidy::cert
+} // namespace clang::tidy::bugprone
diff --git a/clang-tools-extra/clang-tidy/cert/FloatLoopCounter.h b/clang-tools-extra/clang-tidy/bugprone/FloatLoopCounterCheck.h
similarity index 64%
rename from clang-tools-extra/clang-tidy/cert/FloatLoopCounter.h
rename to clang-tools-extra/clang-tidy/bugprone/FloatLoopCounterCheck.h
index d00c036f00f24..43dd9c2c93515 100644
--- a/clang-tools-extra/clang-tidy/cert/FloatLoopCounter.h
+++ b/clang-tools-extra/clang-tidy/bugprone/FloatLoopCounterCheck.h
@@ -6,27 +6,27 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_FLOAT_LOOP_COUNTER_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_FLOAT_LOOP_COUNTER_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FLOATLOOPCOUNTERCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FLOATLOOPCOUNTERCHECK_H
#include "../ClangTidyCheck.h"
-namespace clang::tidy::cert {
+namespace clang::tidy::bugprone {
/// This check diagnoses when the loop induction expression of a for loop has
/// floating-point type. The check corresponds to:
/// https://www.securecoding.cert.org/confluence/display/c/FLP30-C.+Do+not+use+floating-point+variables+as+loop+counters
///
/// For the user-facing documentation see:
-/// https://clang.llvm.org/extra/clang-tidy/checks/cert/flp30-c.html
-class FloatLoopCounter : public ClangTidyCheck {
+/// https://clang.llvm.org/extra/clang-tidy/checks/bugprone/float-loop-counter.html
+class FloatLoopCounterCheck : public ClangTidyCheck {
public:
- FloatLoopCounter(StringRef Name, ClangTidyContext *Context)
+ FloatLoopCounterCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};
-} // namespace clang::tidy::cert
+} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CERT_FLOAT_LOOP_COUNTER_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FLOATLOOPCOUNTERCHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/FoldInitTypeCheck.h b/clang-tools-extra/clang-tidy/bugprone/FoldInitTypeCheck.h
index 119728d972309..ef8b4d11d6517 100644
--- a/clang-tools-extra/clang-tidy/bugprone/FoldInitTypeCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/FoldInitTypeCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FOLD_INIT_TYPE_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FOLD_INIT_TYPE_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FOLDINITTYPECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FOLDINITTYPECHECK_H
#include "../ClangTidyCheck.h"
@@ -39,4 +39,4 @@ class FoldInitTypeCheck : public ClangTidyCheck {
} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FOLD_INIT_TYPE_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_FOLDINITTYPECHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp
index c3db8fa9b3af2..11270e7f34d79 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp
@@ -46,7 +46,7 @@ void ForwardDeclarationNamespaceCheck::check(
const MatchFinder::MatchResult &Result) {
if (const auto *RecordDecl =
Result.Nodes.getNodeAs("record_decl")) {
- StringRef DeclName = RecordDecl->getName();
+ const StringRef DeclName = RecordDecl->getName();
if (RecordDecl->isThisDeclarationADefinition()) {
DeclNameToDefinitions[DeclName].push_back(RecordDecl);
} else {
diff --git a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
index d372cbd798b2e..c1e66f210b8b2 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
@@ -40,7 +40,7 @@ AST_MATCHER(QualType, isEnableIf) {
if (CheckTemplate(BaseType->getAs()))
return true; // Case: enable_if_t< >.
if (const auto *TT = BaseType->getAs())
- if (NestedNameSpecifier Q = TT->getQualifier();
+ if (const NestedNameSpecifier Q = TT->getQualifier();
Q.getKind() == NestedNameSpecifier::Kind::Type)
if (CheckTemplate(Q.getAsType()->getAs()))
return true; // Case: enable_if< >::type.
@@ -67,7 +67,7 @@ void ForwardingReferenceOverloadCheck::registerMatchers(MatchFinder *Finder) {
unless(references(isConstQualified())))))
.bind("parm-var");
- DeclarationMatcher FindOverload =
+ const DeclarationMatcher FindOverload =
cxxConstructorDecl(
hasParameter(0, ForwardingRefParm), unless(isDeleted()),
unless(hasAnyParameter(
@@ -128,8 +128,9 @@ void ForwardingReferenceOverloadCheck::check(
(OtherCtor->isCopyConstructor() ? EnabledCopy : EnabledMove) = true;
}
}
- bool Copy = (!EnabledMove && !DisabledMove && !DisabledCopy) || EnabledCopy;
- bool Move = !DisabledMove || EnabledMove;
+ const bool Copy =
+ (!EnabledMove && !DisabledMove && !DisabledCopy) || EnabledCopy;
+ const bool Move = !DisabledMove || EnabledMove;
if (!Copy && !Move)
return;
diag(Ctor->getLocation(),
diff --git a/clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp
index 2211a0ba24ebc..634d54c2b9bd3 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp
@@ -71,18 +71,18 @@ ImplicitWideningOfMultiplicationResultCheck::includeStddefHeader(
void ImplicitWideningOfMultiplicationResultCheck::handleImplicitCastExpr(
const ImplicitCastExpr *ICE) {
- ASTContext *Context = Result->Context;
+ const ASTContext *Context = Result->Context;
const Expr *E = ICE->getSubExpr()->IgnoreParens();
- QualType Ty = ICE->getType();
- QualType ETy = E->getType();
+ const QualType Ty = ICE->getType();
+ const QualType ETy = E->getType();
assert(!ETy->isDependentType() && !Ty->isDependentType() &&
"Don't expect to ever get here in template Context.");
// This must be a widening cast. Else we do not care.
- unsigned SrcWidth = Context->getIntWidth(ETy);
- unsigned TgtWidth = Context->getIntWidth(Ty);
+ const unsigned SrcWidth = Context->getIntWidth(ETy);
+ const unsigned TgtWidth = Context->getIntWidth(Ty);
if (TgtWidth <= SrcWidth)
return;
@@ -92,7 +92,7 @@ void ImplicitWideningOfMultiplicationResultCheck::handleImplicitCastExpr(
!ETy->isUnsignedIntegerType()) {
if (const auto ConstExprResult = E->getIntegerConstantExpr(*Context)) {
const auto TypeSize = Context->getTypeSize(ETy);
- llvm::APSInt WidenedResult = ConstExprResult->extOrTrunc(TypeSize);
+ const llvm::APSInt WidenedResult = ConstExprResult->extOrTrunc(TypeSize);
if (WidenedResult <= llvm::APSInt::getMaxValue(TypeSize, false) &&
WidenedResult >= llvm::APSInt::getMinValue(TypeSize, false))
return;
@@ -168,7 +168,7 @@ void ImplicitWideningOfMultiplicationResultCheck::handleImplicitCastExpr(
void ImplicitWideningOfMultiplicationResultCheck::handlePointerOffsetting(
const Expr *E) {
- ASTContext *Context = Result->Context;
+ const ASTContext *Context = Result->Context;
// We are looking for a pointer offset operation,
// with one hand being a pointer, and another one being an offset.
@@ -191,19 +191,20 @@ void ImplicitWideningOfMultiplicationResultCheck::handlePointerOffsetting(
IndexExpr = IndexExpr->IgnoreParens();
- QualType IndexExprType = IndexExpr->getType();
+ const QualType IndexExprType = IndexExpr->getType();
// If the index expression's type is not known (i.e. we are in a template),
// we can't do anything here.
if (IndexExprType->isDependentType())
return;
- QualType SSizeTy = Context->getPointerDiffType();
- QualType USizeTy = Context->getSizeType();
- QualType SizeTy = IndexExprType->isSignedIntegerType() ? SSizeTy : USizeTy;
+ const QualType SSizeTy = Context->getPointerDiffType();
+ const QualType USizeTy = Context->getSizeType();
+ const QualType SizeTy =
+ IndexExprType->isSignedIntegerType() ? SSizeTy : USizeTy;
// FIXME: is there a way to actually get the QualType for size_t/ptrdiff_t?
// Note that SizeTy.getAsString() will be unsigned long/..., NOT size_t!
- StringRef TyAsString =
+ const StringRef TyAsString =
IndexExprType->isSignedIntegerType() ? "ptrdiff_t" : "size_t";
// So, is size_t actually wider than the result of the multiplication?
diff --git a/clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp
index b0dd9017c8426..12fa3655ffcd6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp
@@ -43,7 +43,7 @@ void InaccurateEraseCheck::check(const MatchFinder::MatchResult &Result) {
if (!Loc.isMacroID() && EndExpr) {
const auto *AlgCall = Result.Nodes.getNodeAs("alg");
- std::string ReplacementText = std::string(Lexer::getSourceText(
+ const std::string ReplacementText = std::string(Lexer::getSourceText(
CharSourceRange::getTokenRange(EndExpr->getSourceRange()),
*Result.SourceManager, getLangOpts()));
const SourceLocation EndLoc = Lexer::getLocForEndOfToken(
diff --git a/clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp
index 84a99c36523ac..6181ac84f36e3 100644
--- a/clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp
@@ -22,7 +22,7 @@ AST_MATCHER_P(TemplateTypeParmDecl, hasUnnamedDefaultArgument,
Node.getDefaultArgument().getArgument().isNull())
return false;
- TypeLoc DefaultArgTypeLoc =
+ const TypeLoc DefaultArgTypeLoc =
Node.getDefaultArgument().getTypeSourceInfo()->getTypeLoc();
return InnerMatcher.matches(DefaultArgTypeLoc, Finder, Builder);
}
@@ -51,7 +51,7 @@ void IncorrectEnableIfCheck::check(const MatchFinder::MatchResult &Result) {
return;
const SourceManager &SM = *Result.SourceManager;
- SourceLocation RAngleLoc =
+ const SourceLocation RAngleLoc =
SM.getExpansionLoc(EnableIfSpecializationLoc->getRAngleLoc());
auto Diag = diag(EnableIf->getBeginLoc(),
diff --git a/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
index 1e516c1573219..50280d22be0d8 100644
--- a/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
@@ -34,7 +34,7 @@ AST_MATCHER(FunctionType, typeHasNoReturnAttr) {
} // namespace
static Matcher loopEndingStmt(Matcher Internal) {
- Matcher IsNoReturnFunType =
+ const Matcher IsNoReturnFunType =
ignoringParens(functionType(typeHasNoReturnAttr()));
Matcher IsNoReturnDecl =
anyOf(declHasNoReturnAttr(), functionDecl(hasType(IsNoReturnFunType)),
@@ -145,7 +145,7 @@ static std::string getCondVarNames(const Stmt *Cond) {
if (!Child)
continue;
- std::string NewNames = getCondVarNames(Child);
+ const std::string NewNames = getCondVarNames(Child);
if (!Result.empty() && !NewNames.empty())
Result += ", ";
Result += NewNames;
@@ -332,7 +332,7 @@ void InfiniteLoopCheck::check(const MatchFinder::MatchResult &Result) {
Result.Context))
return;
- std::string CondVarNames = getCondVarNames(Cond);
+ const std::string CondVarNames = getCondVarNames(Cond);
if (ShouldHaveConditionVariables && CondVarNames.empty())
return;
diff --git a/clang-tools-extra/clang-tidy/bugprone/IntegerDivisionCheck.h b/clang-tools-extra/clang-tidy/bugprone/IntegerDivisionCheck.h
index 777e31868c961..acab7be7f33c6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/IntegerDivisionCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/IntegerDivisionCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_INTEGER_DIVISION_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_INTEGER_DIVISION_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_INTEGERDIVISIONCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_INTEGERDIVISIONCHECK_H
#include "../ClangTidyCheck.h"
@@ -28,4 +28,4 @@ class IntegerDivisionCheck : public ClangTidyCheck {
} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_INTEGER_DIVISION_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_INTEGERDIVISIONCHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/InvalidEnumDefaultInitializationCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/InvalidEnumDefaultInitializationCheck.cpp
index 76df992f29fc1..f3e94b62f0dbd 100644
--- a/clang-tools-extra/clang-tidy/bugprone/InvalidEnumDefaultInitializationCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/InvalidEnumDefaultInitializationCheck.cpp
@@ -20,6 +20,8 @@ namespace clang::tidy::bugprone {
namespace {
+// Preserve same name as AST_MATCHER(isCompleteAndHasNoZeroValue)
+// NOLINTNEXTLINE(llvm-prefer-static-over-anonymous-namespace)
bool isCompleteAndHasNoZeroValue(const EnumDecl *D) {
const EnumDecl *Definition = D->getDefinition();
return Definition && Definition->isComplete() &&
@@ -149,7 +151,7 @@ void InvalidEnumDefaultInitializationCheck::check(
SourceLocation Loc = InitExpr->getExprLoc();
if (Loc.isInvalid()) {
if (isa(InitExpr)) {
- DynTypedNodeList Parents = ACtx.getParents(*InitExpr);
+ const DynTypedNodeList Parents = ACtx.getParents(*InitExpr);
if (Parents.empty())
return;
@@ -168,7 +170,7 @@ void InvalidEnumDefaultInitializationCheck::check(
// The expression may be implicitly generated for an initialization.
// Search for a parent initialization list with valid source location.
while (InitList->getExprLoc().isInvalid()) {
- DynTypedNodeList Parents = ACtx.getParents(*InitList);
+ const DynTypedNodeList Parents = ACtx.getParents(*InitList);
if (Parents.empty())
return;
InitList = Parents[0].get();
diff --git a/clang-tools-extra/clang-tidy/bugprone/LambdaFunctionNameCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/LambdaFunctionNameCheck.cpp
index fb73e896fdb13..1f666d2a4345f 100644
--- a/clang-tools-extra/clang-tidy/bugprone/LambdaFunctionNameCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/LambdaFunctionNameCheck.cpp
@@ -40,7 +40,7 @@ class MacroExpansionsWithFileAndLine : public PPCallbacks {
bool HasLine = false;
for (const Token &T : MD.getMacroInfo()->tokens()) {
if (T.is(tok::identifier)) {
- StringRef IdentName = T.getIdentifierInfo()->getName();
+ const StringRef IdentName = T.getIdentifierInfo()->getName();
if (IdentName == "__FILE__") {
HasFile = true;
} else if (IdentName == "__LINE__") {
diff --git a/clang-tools-extra/clang-tidy/bugprone/MacroRepeatedSideEffectsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/MacroRepeatedSideEffectsCheck.cpp
index 78a53d12bd312..c79320fbf3304 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MacroRepeatedSideEffectsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/MacroRepeatedSideEffectsCheck.cpp
@@ -127,7 +127,7 @@ unsigned MacroRepeatedPPCallbacks::countArgumentExpansions(
continue;
}
- IdentifierInfo *TII = T.getIdentifierInfo();
+ const IdentifierInfo *TII = T.getIdentifierInfo();
// If not existent, skip it.
if (TII == nullptr)
continue;
diff --git a/clang-tools-extra/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.h b/clang-tools-extra/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.h
index f650145203ce6..c40aef339e91a 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MISPLACED_OPERATOR_IN_STRLEN_IN_ALLOC_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MISPLACED_OPERATOR_IN_STRLEN_IN_ALLOC_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MISPLACEDOPERATORINSTRLENINALLOCCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MISPLACEDOPERATORINSTRLENINALLOCCHECK_H
#include "../ClangTidyCheck.h"
@@ -30,4 +30,4 @@ class MisplacedOperatorInStrlenInAllocCheck : public ClangTidyCheck {
} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MISPLACED_OPERATOR_IN_STRLEN_IN_ALLOC_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MISPLACEDOPERATORINSTRLENINALLOCCHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/MisplacedPointerArithmeticInAllocCheck.h b/clang-tools-extra/clang-tidy/bugprone/MisplacedPointerArithmeticInAllocCheck.h
index e78c30cbb644a..9f6504fe8a911 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MisplacedPointerArithmeticInAllocCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/MisplacedPointerArithmeticInAllocCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MISPLACED_OPERATOR_IN_ALLOC_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MISPLACED_OPERATOR_IN_ALLOC_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MISPLACEDPOINTERARITHMETICINALLOCCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MISPLACEDPOINTERARITHMETICINALLOCCHECK_H
#include "../ClangTidyCheck.h"
@@ -29,4 +29,4 @@ class MisplacedPointerArithmeticInAllocCheck : public ClangTidyCheck {
} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MISPLACED_OPERATOR_IN_ALLOC_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MISPLACEDPOINTERARITHMETICINALLOCCHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp
index d508e2aaba53c..f040235322a4f 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp
@@ -52,8 +52,8 @@ static unsigned getMaxCalculationWidth(const ASTContext &Context,
E = E->IgnoreParenImpCasts();
if (const auto *Bop = dyn_cast(E)) {
- unsigned LHSWidth = getMaxCalculationWidth(Context, Bop->getLHS());
- unsigned RHSWidth = getMaxCalculationWidth(Context, Bop->getRHS());
+ const unsigned LHSWidth = getMaxCalculationWidth(Context, Bop->getLHS());
+ const unsigned RHSWidth = getMaxCalculationWidth(Context, Bop->getRHS());
if (Bop->getOpcode() == BO_Mul)
return LHSWidth + RHSWidth;
if (Bop->getOpcode() == BO_Add)
@@ -79,7 +79,7 @@ static unsigned getMaxCalculationWidth(const ASTContext &Context,
if (Uop->getOpcode() == UO_Not)
return 1024U;
- QualType T = Uop->getType();
+ const QualType T = Uop->getType();
return T->isIntegerType() ? Context.getIntWidth(T) : 1024U;
} else if (const auto *I = dyn_cast(E)) {
return I->getValue().getActiveBits();
@@ -190,10 +190,10 @@ void MisplacedWideningCastCheck::check(const MatchFinder::MatchResult &Result) {
Calc->isTypeDependent() || Calc->isValueDependent())
return;
- ASTContext &Context = *Result.Context;
+ const ASTContext &Context = *Result.Context;
- QualType CastType = Cast->getType();
- QualType CalcType = Calc->getType();
+ const QualType CastType = Cast->getType();
+ const QualType CalcType = Calc->getType();
// Explicit truncation using cast.
if (Context.getIntWidth(CastType) < Context.getIntWidth(CalcType))
diff --git a/clang-tools-extra/clang-tidy/bugprone/MoveForwardingReferenceCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/MoveForwardingReferenceCheck.cpp
index 66559a0e5d7b5..e182df75b1d9a 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MoveForwardingReferenceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/MoveForwardingReferenceCheck.cpp
@@ -21,7 +21,7 @@ static void replaceMoveWithForward(const UnresolvedLookupExpr *Callee,
const SourceManager &SM = Context.getSourceManager();
const LangOptions &LangOpts = Context.getLangOpts();
- CharSourceRange CallRange =
+ const CharSourceRange CallRange =
Lexer::makeFileCharRange(CharSourceRange::getTokenRange(
Callee->getBeginLoc(), Callee->getEndLoc()),
SM, LangOpts);
@@ -39,7 +39,7 @@ static void replaceMoveWithForward(const UnresolvedLookupExpr *Callee,
// std::move(). This will hopefully prevent erroneous replacements if the
// code does unusual things (e.g. create an alias for std::move() in
// another namespace).
- NestedNameSpecifier NNS = Callee->getQualifier();
+ const NestedNameSpecifier NNS = Callee->getQualifier();
switch (NNS.getKind()) {
case NestedNameSpecifier::Kind::Null:
// Called as "move" (i.e. presumably the code had a "using std::move;").
diff --git a/clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.cpp
index 2eff013b2ab7d..78f2017984a96 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.cpp
@@ -86,8 +86,9 @@ MultiLevelImplicitPointerConversionCheck::getCheckTraversalKind() const {
void MultiLevelImplicitPointerConversionCheck::check(
const MatchFinder::MatchResult &Result) {
const auto *MatchedExpr = Result.Nodes.getNodeAs("expr");
- QualType Target = MatchedExpr->getType().getDesugaredType(*Result.Context);
- QualType Source =
+ const QualType Target =
+ MatchedExpr->getType().getDesugaredType(*Result.Context);
+ const QualType Source =
MatchedExpr->getSubExpr()->getType().getDesugaredType(*Result.Context);
diag(MatchedExpr->getExprLoc(), "multilevel pointer conversion from %0 to "
diff --git a/clang-tools-extra/clang-tidy/bugprone/MultipleNewInOneExpressionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/MultipleNewInOneExpressionCheck.cpp
index 17aea9392bd26..b81d2b438d58d 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MultipleNewInOneExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/MultipleNewInOneExpressionCheck.cpp
@@ -51,7 +51,8 @@ namespace {
AST_MATCHER_P(CXXTryStmt, hasHandlerFor,
ast_matchers::internal::Matcher, InnerMatcher) {
- for (unsigned NH = Node.getNumHandlers(), I = 0; I < NH; ++I) {
+ const unsigned NH = Node.getNumHandlers();
+ for (unsigned I = 0; I < NH; ++I) {
const CXXCatchStmt *CatchS = Node.getHandler(I);
// Check for generic catch handler (match anything).
if (CatchS->getCaughtType().isNull())
@@ -66,7 +67,7 @@ AST_MATCHER_P(CXXTryStmt, hasHandlerFor,
}
AST_MATCHER(CXXNewExpr, mayThrow) {
- FunctionDecl *OperatorNew = Node.getOperatorNew();
+ const FunctionDecl *OperatorNew = Node.getOperatorNew();
if (!OperatorNew)
return false;
return !OperatorNew->getType()->castAs()->isNothrow();
diff --git a/clang-tools-extra/clang-tidy/bugprone/MultipleStatementMacroCheck.h b/clang-tools-extra/clang-tidy/bugprone/MultipleStatementMacroCheck.h
index 1a2d4a410b46e..1c3679a893ce5 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MultipleStatementMacroCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/MultipleStatementMacroCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MULTIPLE_STATEMENT_MACRO_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MULTIPLE_STATEMENT_MACRO_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MULTIPLESTATEMENTMACROCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MULTIPLESTATEMENTMACROCHECK_H
#include "../ClangTidyCheck.h"
@@ -29,4 +29,4 @@ class MultipleStatementMacroCheck : public ClangTidyCheck {
} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MULTIPLE_STATEMENT_MACRO_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MULTIPLESTATEMENTMACROCHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
index 287ee95a4db55..501a82d67d558 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
@@ -29,15 +29,15 @@ AST_MATCHER_P(QualType, hasAnyType, std::vector, Names) {
if (Names.empty())
return false;
- std::string Name = Node.getLocalUnqualifiedType().getAsString();
+ const std::string Name = Node.getLocalUnqualifiedType().getAsString();
return llvm::is_contained(Names, Name);
}
AST_MATCHER(FieldDecl, hasIntBitwidth) {
assert(Node.isBitField());
const ASTContext &Ctx = Node.getASTContext();
- unsigned IntBitWidth = Ctx.getIntWidth(Ctx.IntTy);
- unsigned CurrentBitWidth = Node.getBitWidthValue();
+ const unsigned IntBitWidth = Ctx.getIntWidth(Ctx.IntTy);
+ const unsigned CurrentBitWidth = Node.getBitWidthValue();
return IntBitWidth == CurrentBitWidth;
}
@@ -79,7 +79,7 @@ void NarrowingConversionsCheck::registerMatchers(MatchFinder *Finder) {
const auto IsCeilFloorCallExpr = expr(callExpr(callee(functionDecl(
hasAnyName("::ceil", "::std::ceil", "::floor", "::std::floor")))));
- std::vector IgnoreConversionFromTypesVec =
+ const std::vector IgnoreConversionFromTypesVec =
utils::options::parseStringList(IgnoreConversionFromTypes);
// We may want to exclude other types from the checks, such as `size_type`
@@ -243,7 +243,7 @@ struct IntegerRange {
static IntegerRange createFromType(const ASTContext &Context,
const BuiltinType &T) {
if (T.isFloatingPoint()) {
- unsigned PrecisionBits = llvm::APFloatBase::semanticsPrecision(
+ const unsigned PrecisionBits = llvm::APFloatBase::semanticsPrecision(
Context.getFloatTypeSemantics(T.desugar()));
// Contrary to two's complement integer, floating point values are
// symmetric and have the same number of positive and negative values.
@@ -262,8 +262,8 @@ static IntegerRange createFromType(const ASTContext &Context,
return {LowerValue, UpperValue};
}
assert(T.isInteger() && "Unexpected builtin type");
- uint64_t TypeSize = Context.getTypeSize(&T);
- bool IsUnsignedInteger = T.isUnsignedInteger();
+ const uint64_t TypeSize = Context.getTypeSize(&T);
+ const bool IsUnsignedInteger = T.isUnsignedInteger();
return {llvm::APSInt::getMinValue(TypeSize, IsUnsignedInteger),
llvm::APSInt::getMaxValue(TypeSize, IsUnsignedInteger)};
}
@@ -271,15 +271,15 @@ static IntegerRange createFromType(const ASTContext &Context,
static bool isWideEnoughToHold(const ASTContext &Context,
const BuiltinType &FromType,
const BuiltinType &ToType) {
- IntegerRange FromIntegerRange = createFromType(Context, FromType);
- IntegerRange ToIntegerRange = createFromType(Context, ToType);
+ const IntegerRange FromIntegerRange = createFromType(Context, FromType);
+ const IntegerRange ToIntegerRange = createFromType(Context, ToType);
return ToIntegerRange.contains(FromIntegerRange);
}
static bool isWideEnoughToHold(const ASTContext &Context,
const llvm::APSInt &IntegerConstant,
const BuiltinType &ToType) {
- IntegerRange ToIntegerRange = createFromType(Context, ToType);
+ const IntegerRange ToIntegerRange = createFromType(Context, ToType);
return ToIntegerRange.contains(IntegerConstant);
}
@@ -289,13 +289,13 @@ static bool isWideEnoughToHold(const ASTContext &Context,
static bool isFloatExactlyRepresentable(const ASTContext &Context,
const llvm::APFloat &FloatConstant,
const QualType &DestType) {
- unsigned DestWidth = Context.getIntWidth(DestType);
- bool DestSigned = DestType->isSignedIntegerOrEnumerationType();
+ const unsigned DestWidth = Context.getIntWidth(DestType);
+ const bool DestSigned = DestType->isSignedIntegerOrEnumerationType();
llvm::APSInt Result = llvm::APSInt(DestWidth, !DestSigned);
bool IsExact = false;
- bool Overflows = FloatConstant.convertToInteger(
- Result, llvm::APFloat::rmTowardZero, &IsExact) &
- llvm::APFloat::opInvalidOp;
+ const bool Overflows = FloatConstant.convertToInteger(
+ Result, llvm::APFloat::rmTowardZero, &IsExact) &
+ llvm::APFloat::opInvalidOp;
return !Overflows && IsExact;
}
@@ -321,8 +321,8 @@ bool NarrowingConversionsCheck::isWarningInhibitedByEquivalentSize(
// With this option, we don't warn on conversions that have equivalent width
// in bits. eg. uint32 <-> int32.
if (!WarnOnEquivalentBitWidth) {
- uint64_t FromTypeSize = Context.getTypeSize(&FromType);
- uint64_t ToTypeSize = Context.getTypeSize(&ToType);
+ const uint64_t FromTypeSize = Context.getTypeSize(&FromType);
+ const uint64_t ToTypeSize = Context.getTypeSize(&ToType);
if (FromTypeSize == ToTypeSize) {
return true;
}
@@ -406,8 +406,8 @@ void NarrowingConversionsCheck::handleIntegralCast(const ASTContext &Context,
// With this option, we don't warn on conversions that have equivalent width
// in bits. eg. uint32 <-> int32.
if (!WarnOnEquivalentBitWidth) {
- uint64_t FromTypeSize = Context.getTypeSize(FromType);
- uint64_t ToTypeSize = Context.getTypeSize(ToType);
+ const uint64_t FromTypeSize = Context.getTypeSize(FromType);
+ const uint64_t ToTypeSize = Context.getTypeSize(ToType);
if (FromTypeSize == ToTypeSize)
return;
}
@@ -583,7 +583,7 @@ void NarrowingConversionsCheck::handleImplicitCast(
return;
if (handleConditionalOperator(Context, Lhs, Rhs))
return;
- SourceLocation SourceLoc = Lhs.getExprLoc();
+ const SourceLocation SourceLoc = Lhs.getExprLoc();
switch (Cast.getCastKind()) {
case CK_BooleanToSignedIntegral:
handleBooleanToSignedIntegral(Context, SourceLoc, Lhs, Rhs);
diff --git a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.h b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.h
index 9631c71dee64e..e506e5b0315db 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NARROWING_CONVERSIONS_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NARROWING_CONVERSIONS_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NARROWINGCONVERSIONSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NARROWINGCONVERSIONSCHECK_H
#include "../ClangTidyCheck.h"
@@ -108,4 +108,4 @@ class NarrowingConversionsCheck : public ClangTidyCheck {
} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NARROWING_CONVERSIONS_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NARROWINGCONVERSIONSCHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/NondeterministicPointerIterationOrderCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/NondeterministicPointerIterationOrderCheck.cpp
index abde115d10a1b..40305cab81c7f 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NondeterministicPointerIterationOrderCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/NondeterministicPointerIterationOrderCheck.cpp
@@ -60,7 +60,7 @@ void NondeterministicPointerIterationOrderCheck::check(
TemplateArgs[0].getAsType()->isPointerType();
if (IsAlgoArgPointer) {
- SourceRange R = RangeInit->getSourceRange();
+ const SourceRange R = RangeInit->getSourceRange();
diag(R.getBegin(), "iteration of pointers is nondeterministic") << R;
}
}
@@ -69,7 +69,7 @@ void NondeterministicPointerIterationOrderCheck::check(
const auto *SortPointers = Result.Nodes.getNodeAs("sortsemantic");
if ((SortPointers) && !(SortPointers->getBeginLoc().isMacroID())) {
- SourceRange R = SortPointers->getSourceRange();
+ const SourceRange R = SortPointers->getSourceRange();
diag(R.getBegin(), "sorting pointers is nondeterministic") << R;
}
}
diff --git a/clang-tools-extra/clang-tidy/bugprone/NondeterministicPointerIterationOrderCheck.h b/clang-tools-extra/clang-tidy/bugprone/NondeterministicPointerIterationOrderCheck.h
index 054d5804745bc..46b4e12508629 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NondeterministicPointerIterationOrderCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/NondeterministicPointerIterationOrderCheck.h
@@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NONDETERMINISTIC_POINTER_ITERATION_ORDER_CHECK_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NONDETERMINISTIC_POINTER_ITERATION_ORDER_CHECK_H
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NONDETERMINISTICPOINTERITERATIONORDERCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NONDETERMINISTICPOINTERITERATIONORDERCHECK_H
#include "../ClangTidyCheck.h"
@@ -36,4 +36,4 @@ class NondeterministicPointerIterationOrderCheck : public ClangTidyCheck {
} // namespace clang::tidy::bugprone
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NONDETERMINISTIC_POINTER_ITERATION_ORDER_CHECK_H
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NONDETERMINISTICPOINTERITERATIONORDERCHECK_H
diff --git a/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
index 08fae7b59bae5..7198c1b1c8aaf 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
@@ -120,18 +120,18 @@ static int getGivenLength(const MatchFinder::MatchResult &Result) {
if (Result.Nodes.getNodeAs(UnknownLengthName))
return 0;
- if (int Length =
+ if (const int Length =
getLength(Result.Nodes.getNodeAs(WrongLengthExprName), Result))
return Length;
- if (int Length =
+ if (const int Length =
getLength(Result.Nodes.getNodeAs(LengthExprName), Result))
return Length;
// Special case, for example 'strlen("foo")'.
if (const CallExpr *StrlenCE = getStrlenExpr(Result))
if (const Expr *Arg = StrlenCE->getArg(0)->IgnoreImpCasts())
- if (int ArgLength = getLength(Arg, Result))
+ if (const int ArgLength = getLength(Arg, Result))
return ArgLength;
return 0;
@@ -174,9 +174,9 @@ static bool isKnownDest(const MatchFinder::MatchResult &Result) {
// True if the capacity of the destination array is based on the given length,
// therefore we assume that it cannot overflow (e.g. 'malloc(given_length + 1)'
static bool isDestBasedOnGivenLength(const MatchFinder::MatchResult &Result) {
- StringRef DestCapacityExprStr =
+ const StringRef DestCapacityExprStr =
exprToStr(getDestCapacityExpr(Result), Result).trim();
- StringRef LengthExprStr =
+ const StringRef LengthExprStr =
exprToStr(Result.Nodes.getNodeAs(LengthExprName), Result).trim();
return !DestCapacityExprStr.empty() && !LengthExprStr.empty() &&
@@ -226,8 +226,9 @@ isGivenLengthEqualToSrcLength(const MatchFinder::MatchResult &Result) {
if (isStringDataAndLength(Result))
return true;
- int GivenLength = getGivenLength(Result);
- int SrcLength = getLength(Result.Nodes.getNodeAs(SrcExprName), Result);
+ const int GivenLength = getGivenLength(Result);
+ const int SrcLength =
+ getLength(Result.Nodes.getNodeAs