-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[clang-tidy] Filter out googletest TUs in bugprone-unchecked-optional-access #115051
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
8d83ec2
3427fa7
2611af1
2e96cc1
ee10510
d8b311d
9942eee
ed8e56a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #ifndef LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_INPUTS_GTEST_GTEST_H_ | ||
| #define LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_INPUTS_GTEST_GTEST_H_ | ||
|
|
||
| // Mock version of googletest macros. | ||
|
|
||
| // Normally this declares a class, but it isn't relevant for testing. | ||
| #define GTEST_TEST(test_suite_name, test_name) | ||
|
|
||
| // Normally, this has a relatively complex implementation | ||
| // (wrapping the condition evaluation), more complex failure behavior, etc., | ||
| // but we keep it simple for testing. | ||
| #define ASSERT_TRUE(condition) \ | ||
| if (condition) \ | ||
| ; \ | ||
| else \ | ||
| return; // normally "fails" rather than just return | ||
|
|
||
| #endif // LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_INPUTS_GTEST_GTEST_H_ |
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please also add an
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done (there was a false-negative example in |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // RUN: %check_clang_tidy %s bugprone-unchecked-optional-access %t -- -- -I %S/Inputs/unchecked-optional-access | ||
|
|
||
| #include "absl/types/optional.h" | ||
| #include "gtest/gtest.h" | ||
|
|
||
| // All of the warnings are suppressed once we detect that we are in a test TU | ||
| // even the unchecked_value_access case. | ||
|
|
||
| // CHECK-MESSAGE: 1 warning generated | ||
| // CHECK-MESSAGES: Suppressed 1 warnings | ||
|
|
||
| void unchecked_value_access(const absl::optional<int> &opt) { | ||
| opt.value(); | ||
| } | ||
|
|
||
| void assert_true_check_operator_access(const absl::optional<int> &opt) { | ||
| ASSERT_TRUE(opt.has_value()); | ||
| *opt; | ||
| } | ||
|
|
||
| void assert_true_check_value_access(const absl::optional<int> &opt) { | ||
| ASSERT_TRUE(opt.has_value()); | ||
| opt.value(); | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.