Skip to content

Commit 7f6239f

Browse files
committed
[clang-tidy] Fix bugprone-unchecked-optional-access in ClangTidyDiagnosticConsumer
1 parent 4f0c342 commit 7f6239f

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,16 @@ static bool parseFileExtensions(llvm::ArrayRef<std::string> AllFileExtensions,
239239
void ClangTidyContext::setCurrentFile(StringRef File) {
240240
CurrentFile = std::string(File);
241241
CurrentOptions = getOptionsForFile(CurrentFile);
242-
CheckFilter = std::make_unique<CachedGlobList>(*getOptions().Checks);
243-
WarningAsErrorFilter =
244-
std::make_unique<CachedGlobList>(*getOptions().WarningsAsErrors);
245-
if (!parseFileExtensions(*getOptions().HeaderFileExtensions,
242+
CheckFilter =
243+
std::make_unique<CachedGlobList>(getOptions().Checks.value_or(""));
244+
WarningAsErrorFilter = std::make_unique<CachedGlobList>(
245+
getOptions().WarningsAsErrors.value_or(""));
246+
if (!parseFileExtensions(getOptions().HeaderFileExtensions.value_or(
247+
std::vector<std::string>()),
246248
HeaderFileExtensions))
247249
this->configurationDiag("Invalid header file extensions");
248-
if (!parseFileExtensions(*getOptions().ImplementationFileExtensions,
250+
if (!parseFileExtensions(getOptions().ImplementationFileExtensions.value_or(
251+
std::vector<std::string>()),
249252
ImplementationFileExtensions))
250253
this->configurationDiag("Invalid implementation file extensions");
251254
}
@@ -569,7 +572,7 @@ void ClangTidyDiagnosticConsumer::checkFilters(SourceLocation Location,
569572
return;
570573
}
571574

572-
if (!*Context.getOptions().SystemHeaders &&
575+
if (!Context.getOptions().SystemHeaders.value_or(false) &&
573576
(Sources.isInSystemHeader(Location) || Sources.isInSystemMacro(Location)))
574577
return;
575578

@@ -600,15 +603,15 @@ void ClangTidyDiagnosticConsumer::checkFilters(SourceLocation Location,
600603

601604
llvm::Regex *ClangTidyDiagnosticConsumer::getHeaderFilter() {
602605
if (!HeaderFilter)
603-
HeaderFilter =
604-
std::make_unique<llvm::Regex>(*Context.getOptions().HeaderFilterRegex);
606+
HeaderFilter = std::make_unique<llvm::Regex>(
607+
Context.getOptions().HeaderFilterRegex.value_or(""));
605608
return HeaderFilter.get();
606609
}
607610

608611
llvm::Regex *ClangTidyDiagnosticConsumer::getExcludeHeaderFilter() {
609612
if (!ExcludeHeaderFilter)
610613
ExcludeHeaderFilter = std::make_unique<llvm::Regex>(
611-
*Context.getOptions().ExcludeHeaderFilterRegex);
614+
Context.getOptions().ExcludeHeaderFilterRegex.value_or(""));
612615
return ExcludeHeaderFilter.get();
613616
}
614617

0 commit comments

Comments
 (0)