https://github.com/HerrCai0907 requested changes to this pull request.

It would be better to use `GtestCmp` if you really want clang-tidy support 
gtest in this check.
Here is an unfinished example which can match
```int v = 10;
TEST(a, b) {
  std::optional<int> a;
  if (v) {
    a = 1;
  }
  ASSERT_NE(a, std::nullopt);
  a.value();
}
```
```c++
  using namespace ast_matchers;
  auto HasOptionalCallDescendant = hasDescendant(callExpr(callee(cxxMethodDecl(
      ofClass(UncheckedOptionalAccessModel::optionalClassDecl())))));
  Finder->addMatcher(
      decl(anyOf(functionDecl(
                     unless(isExpansionInSystemHeader()),
                     // FIXME: Remove the filter below when lambdas are
                     // well supported by the check.
                     unless(hasDeclContext(cxxRecordDecl(isLambda()))),
                     hasBody(allOf(
                         HasOptionalCallDescendant,
                         unless(hasDescendant(gtestAssert(
                             GtestCmp::Ne,
                             expr(hasType(qualType(hasUnqualifiedDesugaredType(
                                 recordType(hasDeclaration(
                                     UncheckedOptionalAccessModel::
                                         optionalClassDecl())))))),
                             anything())))))),
                 cxxConstructorDecl(hasAnyConstructorInitializer(
                     withInitializer(HasOptionalCallDescendant)))))
          .bind(FuncID),
      this);
```

https://github.com/llvm/llvm-project/pull/115051
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to