[clang-tools-extra] [clang-tidy] Fix some false negatives in `bugprone-throw-keyword-missing` (PR #173748)

via cfe-commits cfe-commits at lists.llvm.org
Sat Dec 27 16:52:06 PST 2025


github-actions[bot] wrote:

<!--LLVM CODE LINT COMMENT: clang-tidy-->


:warning: C/C++ code linter, clang-tidy found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

```bash

git diff -U0 origin/main...HEAD -- clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp |
python3 clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py   -path build -p1 -quiet
```

</details>

<details>
<summary>
View the output from clang-tidy here.
</summary>

```
clang/include/clang/ASTMatchers/ASTMatchersInternal.h:128:26: error: no viable conversion from 'const Matcher<clang::Expr>' to 'const Matcher<clang::Stmt>' [clang-diagnostic-error]
  128 |     return Execute(Arg1, static_cast<const ArgT &>(Args)...);
      |                          ^                         ~~~~
clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp:25:13: note: in instantiation of function template specialization 'clang::ast_matchers::internal::VariadicFunction<clang::ast_matchers::internal::BindableMatcher<clang::Stmt>, clang::ast_matchers::internal::Matcher<clang::Stmt>, &clang::ast_matchers::internal::makeAllOfComposite>::operator()<clang::ast_matchers::internal::Matcher<clang::Expr>>' requested here
   25 |         stmt(anyOf(doStmt(), whileStmt(), forStmt(), compoundStmt(), ifStmt(),
      |             ^
clang/include/clang/ASTMatchers/ASTMatchersInternal.h:568:7: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'const clang::ast_matchers::internal::Matcher<clang::Expr>' to 'const Matcher<clang::Stmt> &' for 1st argument
  568 | class Matcher {
      |       ^~~~~~~
clang/include/clang/ASTMatchers/ASTMatchersInternal.h:568:7: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'const clang::ast_matchers::internal::Matcher<clang::Expr>' to 'Matcher<clang::Stmt> &&' for 1st argument
  568 | class Matcher {
      |       ^~~~~~~
clang/include/clang/ASTMatchers/ASTMatchersInternal.h:578:3: note: candidate template ignored: requirement 'std::is_base_of<clang::Expr, clang::Stmt>::value' was not satisfied [with From = clang::Expr]
  578 |   Matcher(const Matcher<From> &Other,
      |   ^
clang/include/clang/ASTMatchers/ASTMatchersInternal.h:590:3: note: candidate template ignored: requirement 'std::is_same<clang::Stmt, clang::QualType>::value' was not satisfied [with TypeT = clang::Expr]
  590 |   Matcher(const Matcher<TypeT> &Other,
      |   ^
clang/include/clang/ASTMatchers/ASTMatchersInternal.h:571:12: note: explicit constructor is not a candidate
  571 |   explicit Matcher(MatcherInterface<T> *Implementation)
      |            ^
clang/include/clang/ASTMatchers/ASTMatchersInternal.h:666:12: note: explicit constructor is not a candidate
  666 |   explicit Matcher(const DynTypedMatcher &Implementation)
      |            ^
clang/include/clang/ASTMatchers/ASTMatchersInternal.h:624:3: note: candidate function
  624 |   operator DynTypedMatcher() const & { return Implementation; }
      |   ^
clang/include/clang/ASTMatchers/ASTMatchersInternal.h:626:3: note: candidate function not viable: 'this' argument has type 'const clang::ast_matchers::internal::Matcher<clang::Expr>', but method is not marked const
  626 |   operator DynTypedMatcher() && { return std::move(Implementation); }
      |   ^
clang/include/clang/ASTMatchers/ASTMatchersInternal.h:1363:13: error: no matching conversion for functional-style cast from 'const clang::ast_matchers::internal::VariadicDynCastAllOfMatcher<clang::Stmt, clang::AttributedStmt>' to 'Matcher<clang::Stmt>' [clang-diagnostic-error]
 1363 |     return {Matcher<T>(std::get<Is>(Params))...};
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clang/include/clang/ASTMatchers/ASTMatchersInternal.h:1355:16: note: in instantiation of function template specialization 'clang::ast_matchers::internal::VariadicOperatorMatcher<clang::ast_matchers::internal::BindableMatcher<clang::Stmt>, clang::ast_matchers::internal::BindableMatcher<clang::Stmt>, clang::ast_matchers::internal::BindableMatcher<clang::Stmt>, clang::ast_matchers::internal::BindableMatcher<clang::Stmt>, clang::ast_matchers::internal::BindableMatcher<clang::Stmt>, clang::ast_matchers::internal::BindableMatcher<clang::Stmt>, clang::ast_matchers::internal::BindableMatcher<clang::Stmt>, const clang::ast_matchers::internal::VariadicDynCastAllOfMatcher<clang::Stmt, clang::AttributedStmt> &>::getMatchers<clang::Stmt, 0UL, 1UL, 2UL, 3UL, 4UL, 5UL, 6UL, 7UL>' requested here
 1355 |                getMatchers<T>(std::index_sequence_for<Ps...>()))
      |                ^
clang-tools-extra/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp:25:14: note: in instantiation of function template specialization 'clang::ast_matchers::internal::VariadicOperatorMatcher<clang::ast_matchers::internal::BindableMatcher<clang::Stmt>, clang::ast_matchers::internal::BindableMatcher<clang::Stmt>, clang::ast_matchers::internal::BindableMatcher<clang::Stmt>, clang::ast_matchers::internal::BindableMatcher<clang::Stmt>, clang::ast_matchers::internal::BindableMatcher<clang::Stmt>, clang::ast_matchers::internal::BindableMatcher<clang::Stmt>, clang::ast_matchers::internal::BindableMatcher<clang::Stmt>, const clang::ast_matchers::internal::VariadicDynCastAllOfMatcher<clang::Stmt, clang::AttributedStmt> &>::operator Matcher<clang::Stmt>' requested here
   25 |         stmt(anyOf(doStmt(), whileStmt(), forStmt(), compoundStmt(), ifStmt(),
      |              ^
clang/include/clang/ASTMatchers/ASTMatchersInternal.h:568:7: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'const clang::ast_matchers::internal::VariadicDynCastAllOfMatcher<clang::Stmt, clang::AttributedStmt>' to 'const Matcher<clang::Stmt>' for 1st argument
  568 | class Matcher {
      |       ^~~~~~~
clang/include/clang/ASTMatchers/ASTMatchersInternal.h:568:7: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'const clang::ast_matchers::internal::VariadicDynCastAllOfMatcher<clang::Stmt, clang::AttributedStmt>' to 'Matcher<clang::Stmt>' for 1st argument
  568 | class Matcher {
      |       ^~~~~~~
clang/include/clang/ASTMatchers/ASTMatchersInternal.h:571:12: note: candidate constructor not viable: no known conversion from 'const clang::ast_matchers::internal::VariadicDynCastAllOfMatcher<clang::Stmt, clang::AttributedStmt>' to 'MatcherInterface<clang::Stmt> *' for 1st argument
  571 |   explicit Matcher(MatcherInterface<T> *Implementation)
      |            ^       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clang/include/clang/ASTMatchers/ASTMatchersInternal.h:666:12: note: candidate constructor not viable: no known conversion from 'const clang::ast_matchers::internal::VariadicDynCastAllOfMatcher<clang::Stmt, clang::AttributedStmt>' to 'const DynTypedMatcher' for 1st argument
  666 |   explicit Matcher(const DynTypedMatcher &Implementation)
      |            ^       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clang/include/clang/ASTMatchers/ASTMatchersInternal.h:578:3: note: candidate template ignored: could not match 'Matcher' against 'clang::ast_matchers::internal::VariadicDynCastAllOfMatcher'
  578 |   Matcher(const Matcher<From> &Other,
      |   ^
clang/include/clang/ASTMatchers/ASTMatchersInternal.h:590:3: note: candidate template ignored: could not match 'Matcher' against 'clang::ast_matchers::internal::VariadicDynCastAllOfMatcher'
  590 |   Matcher(const Matcher<TypeT> &Other,
      |   ^
```

</details>


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


More information about the cfe-commits mailing list