Skip to content

Commit 50ff6d6

Browse files
Incorporate Review Comments
1 parent 46bf9cb commit 50ff6d6

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ SuspiciousIncludeCheck::SuspiciousIncludeCheck(StringRef Name,
4141
: ClangTidyCheck(Name, Context),
4242
HeaderFileExtensions(Context->getHeaderFileExtensions()),
4343
ImplementationFileExtensions(Context->getImplementationFileExtensions()),
44-
IgnoredRegex(Options.get("IgnoredRegex")) {}
44+
IgnoredRegexString(Options.get("IgnoredRegex")),
45+
IgnoredRegex(IgnoredRegexString.value_or(StringRef{})) {}
4546

4647
void SuspiciousIncludeCheck::registerPPCallbacks(
4748
const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
@@ -50,8 +51,8 @@ void SuspiciousIncludeCheck::registerPPCallbacks(
5051
}
5152

5253
void SuspiciousIncludeCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
53-
if (IgnoredRegex.has_value())
54-
Options.store(Opts, "IgnoredRegex", IgnoredRegex.value());
54+
if (IgnoredRegexString.has_value())
55+
Options.store(Opts, "IgnoredRegex", IgnoredRegexString.value());
5556
}
5657

5758
void SuspiciousIncludePPCallbacks::InclusionDirective(
@@ -62,9 +63,10 @@ void SuspiciousIncludePPCallbacks::InclusionDirective(
6263
if (IncludeTok.getIdentifierInfo()->getPPKeywordID() == tok::pp_import)
6364
return;
6465

65-
if (Check.IgnoredRegex.has_value())
66-
if (llvm::Regex Regex{Check.IgnoredRegex.value()}; Regex.match(FileName))
67-
return;
66+
if (Check.IgnoredRegexString.has_value() &&
67+
Check.IgnoredRegex.match(FileName)) {
68+
return;
69+
}
6870

6971
SourceLocation DiagLoc = FilenameRange.getBegin().getLocWithOffset(1);
7072

clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class SuspiciousIncludeCheck : public ClangTidyCheck {
3131

3232
FileExtensionsSet HeaderFileExtensions;
3333
FileExtensionsSet ImplementationFileExtensions;
34-
std::optional<StringRef> IgnoredRegex;
34+
std::optional<StringRef> IgnoredRegexString;
35+
llvm::Regex IgnoredRegex;
3536
};
3637

3738
} // namespace clang::tidy::bugprone

clang-tools-extra/test/clang-tidy/checkers/bugprone/suspicious-include.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// RUN: %check_clang_tidy %s bugprone-suspicious-include %t -- -config="{CheckOptions: {bugprone-suspicious-include.IgnoredRegex: 'moc_.*'}"} -- -isystem %clang_tidy_headers -fmodules
1+
// RUN: %check_clang_tidy %s bugprone-suspicious-include %t -- \
2+
// RUN: -config="{CheckOptions: {bugprone-suspicious-include.IgnoredRegex: 'moc_.*'}"} -- \
3+
// RUN: -isystem %clang_tidy_headers -fmodules
24

35
// clang-format off
46

0 commit comments

Comments
 (0)