[clang-tidy] Correctly ignore function templates in derived-method-shadowing-base-method (#185741) (#185875)
This commit fixes a false positive in the derived-method-shadowin-base-method clang-tidy check, as described in [ticket 185741](https://github.com/llvm/llvm-project/issues/185741) Fixes #185741 --------- Co-authored-by: Tom James <tom.james@siemens.com> Co-authored-by: Zeyi Xu <mitchell.xu2@gmail.com>
This commit is contained in:
parent
de514fbaba
commit
bb86440c60
@ -81,6 +81,10 @@ AST_MATCHER(CXXMethodDecl, nameCollidesWithMethodInBase) {
|
||||
// similar matchers are used elsewhere in LLVM
|
||||
AST_MATCHER(CXXMethodDecl, isOutOfLine) { return Node.isOutOfLine(); }
|
||||
|
||||
AST_MATCHER(CXXMethodDecl, isTemplate) {
|
||||
return Node.getDescribedFunctionTemplate() != nullptr;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
DerivedMethodShadowingBaseMethodCheck::DerivedMethodShadowingBaseMethodCheck(
|
||||
@ -94,8 +98,8 @@ void DerivedMethodShadowingBaseMethodCheck::registerMatchers(
|
||||
unless(anyOf(isOutOfLine(), isStaticStorageClass(), isImplicit(),
|
||||
cxxConstructorDecl(), isOverride(), isPrivate(),
|
||||
// isFinal(), //included with isOverride,
|
||||
// Templates are not handled yet
|
||||
ast_matchers::isTemplateInstantiation(),
|
||||
// TODO: Templates are not handled yet
|
||||
isTemplate(), ast_matchers::isTemplateInstantiation(),
|
||||
ast_matchers::isExplicitTemplateSpecialization())),
|
||||
ofClass(cxxRecordDecl(isDerivedFrom(cxxRecordDecl()))
|
||||
.bind("derived_class")),
|
||||
|
||||
@ -204,6 +204,10 @@ Changes in existing checks
|
||||
<clang-tidy/checks/bugprone/casting-through-void>` check by running only on
|
||||
C++ files because suggested ``reinterpret_cast`` is not available in pure C.
|
||||
|
||||
- Improved :doc:`bugprone-derived-method-shadowing-base-method
|
||||
<clang-tidy/checks/bugprone/derived-method-shadowing-base-method>` check by
|
||||
correctly ignoring function templates.
|
||||
|
||||
- Improved :doc:`bugprone-exception-escape
|
||||
<clang-tidy/checks/bugprone/exception-escape>` check by adding
|
||||
`TreatFunctionsWithoutSpecificationAsThrowing` option to support reporting
|
||||
|
||||
@ -137,3 +137,10 @@ public:
|
||||
void methodWithArg(MyInt *I);
|
||||
void methodWithArg(MyInt const* I);
|
||||
};
|
||||
|
||||
class R: public Base
|
||||
{
|
||||
public:
|
||||
template <typename T>
|
||||
Base* getThis();
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user