[clang-tools-extra] [clang-tidy] Filter out googletest TUs in bugprone-unchecked-optional-access (PR #115051)

Jan Voung via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 6 14:18:52 PST 2024


jvoung wrote:

> > we're not (fully) understanding the content
> 
> My thinking was that we don't even need to understand the content, we simply exclude code that is contained within any of the problematic public macros. This sounds like it should be possible to do? Unfortunately I don't know the details on how this could be implemented, hopefully other reviewers know better?
> 
> Otherwise ChatGPT seems to give useful ideas on how to skip a matched result contained within an `ASSERT` macro (obviously untested):
> 
> ```
>   if (Lexer::getImmediateMacroName(Loc, SM, Result.Context->getLangOpts()) == "ASSERT") {
>     // The call is within ASSERT, no diagnostic needed.
>     return;
>   }
> ```

That doesn't handle some cases like:

```
auto opt = DoSomeSetup(...)
ASSERT_TRUE(opt.has_value())
T x = DoMoreSetup(*opt)  // warn right here, since we didn't interpret the above ASSERT_TRUE (or other ways to check)

EXPECT_EQ(FunctionToTest(x), ...);
```

Sometimes the `*opt` may be within a macro, but not always.

https://github.com/llvm/llvm-project/pull/115051


More information about the cfe-commits mailing list