Skip to content

Commit 899cd2c

Browse files
author
Tom James
committed
Re-name to bugprone-derived-method-shadowing-base-method
1 parent c376c45 commit 899cd2c

File tree

8 files changed

+33
-28
lines changed

8 files changed

+33
-28
lines changed

clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "CopyConstructorInitCheck.h"
2424
#include "CrtpConstructorAccessibilityCheck.h"
2525
#include "DanglingHandleCheck.h"
26+
#include "DerivedMethodShadowingBaseMethodCheck.h"
2627
#include "DynamicStaticInitializersCheck.h"
2728
#include "EasilySwappableParametersCheck.h"
2829
#include "EmptyCatchCheck.h"
@@ -42,7 +43,6 @@
4243
#include "LambdaFunctionNameCheck.h"
4344
#include "MacroParenthesesCheck.h"
4445
#include "MacroRepeatedSideEffectsCheck.h"
45-
#include "MethodHidingCheck.h"
4646
#include "MisleadingSetterOfReferenceCheck.h"
4747
#include "MisplacedOperatorInStrlenInAllocCheck.h"
4848
#include "MisplacedPointerArithmeticInAllocCheck.h"
@@ -154,7 +154,8 @@ class BugproneModule : public ClangTidyModule {
154154
"bugprone-incorrect-enable-if");
155155
CheckFactories.registerCheck<IncorrectEnableSharedFromThisCheck>(
156156
"bugprone-incorrect-enable-shared-from-this");
157-
CheckFactories.registerCheck<MethodHidingCheck>("bugprone-method-hiding");
157+
CheckFactories.registerCheck<DerivedMethodShadowingBaseMethodCheck>(
158+
"bugprone-derived-method-shadowing-base-method");
158159
CheckFactories.registerCheck<UnintendedCharOstreamOutputCheck>(
159160
"bugprone-unintended-char-ostream-output");
160161
CheckFactories.registerCheck<ReturnConstRefFromParameterCheck>(

clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ add_clang_library(clangTidyBugproneModule STATIC
3131
IncorrectEnableIfCheck.cpp
3232
IncorrectEnableSharedFromThisCheck.cpp
3333
InvalidEnumDefaultInitializationCheck.cpp
34-
MethodHidingCheck.cpp
34+
DerivedMethodShadowingBaseMethodCheck.cpp
3535
UnintendedCharOstreamOutputCheck.cpp
3636
ReturnConstRefFromParameterCheck.cpp
3737
SuspiciousStringviewDataUsageCheck.cpp

clang-tools-extra/clang-tidy/bugprone/MethodHidingCheck.cpp renamed to clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "MethodHidingCheck.h"
9+
#include "DerivedMethodShadowingBaseMethodCheck.h"
1010
#include "clang/ASTMatchers/ASTMatchFinder.h"
1111
#include "clang/ASTMatchers/ASTMatchers.h"
1212
#include <stack>
@@ -83,10 +83,12 @@ AST_MATCHER(CXXMethodDecl, isOutOfLine) { return Node.isOutOfLine(); }
8383

8484
} // namespace
8585

86-
MethodHidingCheck::MethodHidingCheck(StringRef Name, ClangTidyContext *Context)
86+
DerivedMethodShadowingBaseMethodCheck::DerivedMethodShadowingBaseMethodCheck(
87+
StringRef Name, ClangTidyContext *Context)
8788
: ClangTidyCheck(Name, Context) {}
8889

89-
void MethodHidingCheck::registerMatchers(MatchFinder *Finder) {
90+
void DerivedMethodShadowingBaseMethodCheck::registerMatchers(
91+
MatchFinder *Finder) {
9092
Finder->addMatcher(
9193
cxxMethodDecl(
9294
unless(anyOf(isOutOfLine(), isStaticStorageClass(), isImplicit(),
@@ -103,7 +105,8 @@ void MethodHidingCheck::registerMatchers(MatchFinder *Finder) {
103105
this);
104106
}
105107

106-
void MethodHidingCheck::check(const MatchFinder::MatchResult &Result) {
108+
void DerivedMethodShadowingBaseMethodCheck::check(
109+
const MatchFinder::MatchResult &Result) {
107110
const auto *ShadowingMethod =
108111
Result.Nodes.getNodeAs<CXXMethodDecl>("shadowing_method");
109112
const auto *DerivedClass =

clang-tools-extra/clang-tidy/bugprone/MethodHidingCheck.h renamed to clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_METHODHIDINGCHECK_H
10-
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_METHODHIDINGCHECK_H
9+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DERIVEDMETHODSHADOWINGBASEMETHODCHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DERIVEDMETHODSHADOWINGBASEMETHODCHECK_H
1111

1212
#include "../ClangTidyCheck.h"
1313

@@ -19,10 +19,11 @@ namespace clang::tidy::bugprone {
1919
/// This anti-pattern is a Liskov violation.
2020
///
2121
/// For the user-facing documentation see:
22-
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/method-hiding.html
23-
class MethodHidingCheck : public ClangTidyCheck {
22+
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/derived-method-shadowing-base-method.html
23+
class DerivedMethodShadowingBaseMethodCheck : public ClangTidyCheck {
2424
public:
25-
MethodHidingCheck(StringRef Name, ClangTidyContext *Context);
25+
DerivedMethodShadowingBaseMethodCheck(StringRef Name,
26+
ClangTidyContext *Context);
2627
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
2728
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
2829
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
@@ -35,4 +36,4 @@ class MethodHidingCheck : public ClangTidyCheck {
3536

3637
} // namespace clang::tidy::bugprone
3738

38-
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_METHODHIDINGCHECK_H
39+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DERIVEDMETHODSHADOWINGBASEMETHODCHECK_H

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ New checks
135135
Detects default initialization (to 0) of variables with ``enum`` type where
136136
the enum has no enumerator with value of 0.
137137

138-
- New :doc:`bugprone-method-hiding
139-
<clang-tidy/checks/bugprone/method-hiding>` check.
138+
- New :doc:`bugprone-derived-method-shadowing-base-method
139+
<clang-tidy/checks/bugprone/derived-method-shadowing-base-method>` check.
140140

141141
Finds derived class methods that shadow a (non-virtual) base class method.
142142

clang-tools-extra/docs/clang-tidy/checks/bugprone/method-hiding.rst renamed to clang-tools-extra/docs/clang-tidy/checks/bugprone/derived-method-shadowing-base-method.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
.. title:: clang-tidy - bugprone-method-hiding
1+
.. title:: clang-tidy - bugprone-derived-method-shadowing-base-method
22

3-
bugprone-method-hiding
4-
=========================
3+
bugprone-derived-method-shadowing-base-method
4+
=============================================
55

6-
Finds derived class methods that hide a (non-virtual) base class method.
6+
Finds derived class methods that shadow a (non-virtual) base class method.
77

8-
In order to be considered "hiding", methods must have the same signature
8+
In order to be considered "shadowing", methods must have the same signature
99
(i.e. the same name, same number of parameters, same parameter types, etc).
1010
Only checks public, non-templated methods.
1111

clang-tools-extra/docs/clang-tidy/checks/list.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ Clang-Tidy Checks
9191
:doc:`bugprone-copy-constructor-init <bugprone/copy-constructor-init>`, "Yes"
9292
:doc:`bugprone-crtp-constructor-accessibility <bugprone/crtp-constructor-accessibility>`, "Yes"
9393
:doc:`bugprone-dangling-handle <bugprone/dangling-handle>`,
94+
:doc:`bugprone-derived-method-shadowing-base-method <bugprone/derived-method-shadowing-base-method>`,
9495
:doc:`bugprone-dynamic-static-initializers <bugprone/dynamic-static-initializers>`,
9596
:doc:`bugprone-easily-swappable-parameters <bugprone/easily-swappable-parameters>`,
9697
:doc:`bugprone-empty-catch <bugprone/empty-catch>`,
@@ -110,7 +111,6 @@ Clang-Tidy Checks
110111
:doc:`bugprone-lambda-function-name <bugprone/lambda-function-name>`,
111112
:doc:`bugprone-macro-parentheses <bugprone/macro-parentheses>`, "Yes"
112113
:doc:`bugprone-macro-repeated-side-effects <bugprone/macro-repeated-side-effects>`,
113-
:doc:`bugprone-method-hiding <bugprone/method-hiding>`
114114
:doc:`bugprone-misleading-setter-of-reference <bugprone/misleading-setter-of-reference>`,
115115
:doc:`bugprone-misplaced-operator-in-strlen-in-alloc <bugprone/misplaced-operator-in-strlen-in-alloc>`, "Yes"
116116
:doc:`bugprone-misplaced-pointer-arithmetic-in-alloc <bugprone/misplaced-pointer-arithmetic-in-alloc>`, "Yes"
@@ -250,12 +250,12 @@ Clang-Tidy Checks
250250
:doc:`linuxkernel-must-check-errs <linuxkernel/must-check-errs>`,
251251
:doc:`llvm-header-guard <llvm/header-guard>`,
252252
:doc:`llvm-include-order <llvm/include-order>`, "Yes"
253-
:doc:`llvm-use-new-mlir-op-builder <llvm/use-new-mlir-op-builder>`, "Yes"
254253
:doc:`llvm-namespace-comment <llvm/namespace-comment>`,
255254
:doc:`llvm-prefer-isa-or-dyn-cast-in-conditionals <llvm/prefer-isa-or-dyn-cast-in-conditionals>`, "Yes"
256255
:doc:`llvm-prefer-register-over-unsigned <llvm/prefer-register-over-unsigned>`, "Yes"
257256
:doc:`llvm-prefer-static-over-anonymous-namespace <llvm/prefer-static-over-anonymous-namespace>`,
258257
:doc:`llvm-twine-local <llvm/twine-local>`, "Yes"
258+
:doc:`llvm-use-new-mlir-op-builder <llvm/use-new-mlir-op-builder>`, "Yes"
259259
:doc:`llvmlibc-callee-namespace <llvmlibc/callee-namespace>`,
260260
:doc:`llvmlibc-implementation-in-namespace <llvmlibc/implementation-in-namespace>`,
261261
:doc:`llvmlibc-inline-function-decl <llvmlibc/inline-function-decl>`, "Yes"

clang-tools-extra/test/clang-tidy/checkers/bugprone/method-hiding.cpp renamed to clang-tools-extra/test/clang-tidy/checkers/bugprone/derived-method-shadowing-base-method.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %check_clang_tidy %s bugprone-method-hiding %t
1+
// RUN: %check_clang_tidy %s bugprone-derived-method-shadowing-base-method %t
22

33
class Base
44
{
@@ -12,7 +12,7 @@ class A : public Base
1212
{
1313
public:
1414
void method();
15-
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'A::method' hides same method in 'Base' [bugprone-method-hiding]
15+
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'A::method' hides same method in 'Base' [bugprone-derived-method-shadowing-base-method]
1616
};
1717

1818
// only declaration should be checked
@@ -36,7 +36,7 @@ class E : public D
3636
{
3737
public:
3838
void method();
39-
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'E::method' hides same method in 'Base' [bugprone-method-hiding]
39+
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'E::method' hides same method in 'Base' [bugprone-derived-method-shadowing-base-method]
4040
};
4141

4242
class H : public Base
@@ -51,7 +51,7 @@ class I : public Base
5151
public:
5252
// test with inline implementation
5353
void method()
54-
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'I::method' hides same method in 'Base' [bugprone-method-hiding]
54+
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'I::method' hides same method in 'Base' [bugprone-derived-method-shadowing-base-method]
5555
{
5656

5757
}
@@ -82,10 +82,10 @@ class L : public Base
8282
public:
8383
// not same signature (take const ref) but still ambiguous
8484
void methodWithArg(int const& I);
85-
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'L::methodWithArg' hides same method in 'Base' [bugprone-method-hiding]
85+
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'L::methodWithArg' hides same method in 'Base' [bugprone-derived-method-shadowing-base-method]
8686

8787
void methodWithArg(int const I);
88-
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'L::methodWithArg' hides same method in 'Base' [bugprone-method-hiding]
88+
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'L::methodWithArg' hides same method in 'Base' [bugprone-derived-method-shadowing-base-method]
8989

9090
void methodWithArg(int *I);
9191
void methodWithArg(int const* I);

0 commit comments

Comments
 (0)