[clang-tools-extra] [clang-tidy] Filter out googletest TUs in bugprone-unchecked-optional-access (PR #115051)
Julian Schmidt via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 7 00:56:59 PST 2025
================
@@ -40,11 +40,30 @@ void UncheckedOptionalAccessCheck::registerMatchers(MatchFinder *Finder) {
this);
}
+void UncheckedOptionalAccessCheck::onStartOfTranslationUnit() {
+ // Reset the flag for each TU.
+ is_test_tu_ = false;
+}
+
void UncheckedOptionalAccessCheck::check(
const MatchFinder::MatchResult &Result) {
- if (Result.SourceManager->getDiagnostics().hasUncompilableErrorOccurred())
+ // The googletest assertion macros are not currently recognized, so we have
+ // many false positives in tests. So, do not check functions in a test TU
+ // if the option ignore_test_tus_ is set.
+ if ((ignore_test_tus_ && is_test_tu_) ||
+ Result.SourceManager->getDiagnostics().hasUncompilableErrorOccurred())
----------------
5chmidti wrote:
Couldn't this be moved to onStartOfTranslationUnit?
https://github.com/llvm/llvm-project/pull/115051
More information about the cfe-commits
mailing list