Skip to content

Commit e0379b8

Browse files
authored
[clang-tidy] Moved Multiple Inheritence check from fuchsia to misc module (#171565)
Resolves: [#171136](#171136)
1 parent 62ee2cf commit e0379b8

File tree

11 files changed

+82
-60
lines changed

11 files changed

+82
-60
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ add_clang_library(clangTidyFuchsiaModule STATIC
77
DefaultArgumentsCallsCheck.cpp
88
DefaultArgumentsDeclarationsCheck.cpp
99
FuchsiaTidyModule.cpp
10-
MultipleInheritanceCheck.cpp
1110
OverloadedOperatorCheck.cpp
1211
StaticallyConstructedObjectsCheck.cpp
1312
TemporaryObjectsCheck.cpp
@@ -17,6 +16,7 @@ add_clang_library(clangTidyFuchsiaModule STATIC
1716
LINK_LIBS
1817
clangTidy
1918
clangTidyGoogleModule
19+
clangTidyMiscModule
2020
clangTidyUtils
2121

2222
DEPENDS

clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
#include "../ClangTidyModule.h"
1111
#include "../ClangTidyModuleRegistry.h"
1212
#include "../google/UnnamedNamespaceInHeaderCheck.h"
13+
#include "../misc/MultipleInheritanceCheck.h"
1314
#include "DefaultArgumentsCallsCheck.h"
1415
#include "DefaultArgumentsDeclarationsCheck.h"
15-
#include "MultipleInheritanceCheck.h"
1616
#include "OverloadedOperatorCheck.h"
1717
#include "StaticallyConstructedObjectsCheck.h"
1818
#include "TemporaryObjectsCheck.h"
@@ -34,7 +34,7 @@ class FuchsiaModule : public ClangTidyModule {
3434
"fuchsia-default-arguments-declarations");
3535
CheckFactories.registerCheck<google::build::UnnamedNamespaceInHeaderCheck>(
3636
"fuchsia-header-anon-namespaces");
37-
CheckFactories.registerCheck<MultipleInheritanceCheck>(
37+
CheckFactories.registerCheck<misc::MultipleInheritanceCheck>(
3838
"fuchsia-multiple-inheritance");
3939
CheckFactories.registerCheck<OverloadedOperatorCheck>(
4040
"fuchsia-overloaded-operator");

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ add_clang_library(clangTidyMiscModule STATIC
2828
MisleadingBidirectionalCheck.cpp
2929
MisleadingIdentifierCheck.cpp
3030
MisplacedConstCheck.cpp
31+
MultipleInheritanceCheck.cpp
3132
NewDeleteOverloadsCheck.cpp
3233
NoRecursionCheck.cpp
3334
NonCopyableObjectsCheck.cpp

clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "MisleadingBidirectionalCheck.h"
1919
#include "MisleadingIdentifierCheck.h"
2020
#include "MisplacedConstCheck.h"
21+
#include "MultipleInheritanceCheck.h"
2122
#include "NewDeleteOverloadsCheck.h"
2223
#include "NoRecursionCheck.h"
2324
#include "NonCopyableObjectsCheck.h"
@@ -57,6 +58,8 @@ class MiscModule : public ClangTidyModule {
5758
CheckFactories.registerCheck<MisleadingIdentifierCheck>(
5859
"misc-misleading-identifier");
5960
CheckFactories.registerCheck<MisplacedConstCheck>("misc-misplaced-const");
61+
CheckFactories.registerCheck<MultipleInheritanceCheck>(
62+
"misc-multiple-inheritance");
6063
CheckFactories.registerCheck<NewDeleteOverloadsCheck>(
6164
"misc-new-delete-overloads");
6265
CheckFactories.registerCheck<NoRecursionCheck>("misc-no-recursion");

clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp renamed to clang-tools-extra/clang-tidy/misc/MultipleInheritanceCheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
using namespace clang;
1414
using namespace clang::ast_matchers;
1515

16-
namespace clang::tidy::fuchsia {
16+
namespace clang::tidy::misc {
1717

1818
namespace {
1919
AST_MATCHER(CXXRecordDecl, hasBases) {
@@ -74,4 +74,4 @@ void MultipleInheritanceCheck::check(const MatchFinder::MatchResult &Result) {
7474
"pure virtual is discouraged");
7575
}
7676

77-
} // namespace clang::tidy::fuchsia
77+
} // namespace clang::tidy::misc

clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.h renamed to clang-tools-extra/clang-tidy/misc/MultipleInheritanceCheck.h

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

9-
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_MULTIPLEINHERITANCECHECK_H
10-
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_MULTIPLEINHERITANCECHECK_H
9+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MULTIPLEINHERITANCECHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MULTIPLEINHERITANCECHECK_H
1111

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

14-
namespace clang::tidy::fuchsia {
14+
namespace clang::tidy::misc {
1515

1616
/// Multiple implementation inheritance is discouraged.
1717
///
1818
/// For the user-facing documentation see:
19-
/// https://clang.llvm.org/extra/clang-tidy/checks/fuchsia/multiple-inheritance.html
19+
/// https://clang.llvm.org/extra/clang-tidy/checks/misc/multiple-inheritance.html
2020
class MultipleInheritanceCheck : public ClangTidyCheck {
2121
public:
2222
MultipleInheritanceCheck(StringRef Name, ClangTidyContext *Context)
@@ -38,6 +38,6 @@ class MultipleInheritanceCheck : public ClangTidyCheck {
3838
llvm::DenseMap<const CXXRecordDecl *, bool> InterfaceMap;
3939
};
4040

41-
} // namespace clang::tidy::fuchsia
41+
} // namespace clang::tidy::misc
4242

43-
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_MULTIPLEINHERITANCECHECK_H
43+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MULTIPLEINHERITANCECHECK_H

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,11 @@ New check aliases
331331
<clang-tidy/checks/bugprone/copy-constructor-mutates-argument>`
332332
keeping initial check as an alias to the new one.
333333

334+
- Renamed :doc:`fuchsia-multiple-inheritance <clang-tidy/checks/fuchsia/multiple-inheritance>` to
335+
:doc:`misc-multiple-inheritance
336+
<clang-tidy/checks/misc/multiple-inheritance>`
337+
keeping initial check as an alias to the new one.
338+
334339
- Renamed :doc:`google-readability-casting <clang-tidy/checks/google/readability-casting>` to
335340
:doc:`modernize-avoid-c-style-cast
336341
<clang-tidy/checks/modernize/avoid-c-style-cast>`

clang-tools-extra/docs/clang-tidy/checks/fuchsia/multiple-inheritance.rst

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,7 @@
33
fuchsia-multiple-inheritance
44
============================
55

6-
Warns if a class inherits from multiple classes that are not pure virtual.
6+
The `fuchsia-multiple-inheritance` check is an alias, please See
7+
:doc:`misc-multiple-inheritance <../misc/multiple-inheritance>` for details.
78

8-
For example, declaring a class that inherits from multiple concrete classes is
9-
disallowed:
10-
11-
.. code-block:: c++
12-
13-
class Base_A {
14-
public:
15-
virtual int foo() { return 0; }
16-
};
17-
18-
class Base_B {
19-
public:
20-
virtual int bar() { return 0; }
21-
};
22-
23-
// Warning
24-
class Bad_Child1 : public Base_A, Base_B {};
25-
26-
A class that inherits from a pure virtual is allowed:
27-
28-
.. code-block:: c++
29-
30-
class Interface_A {
31-
public:
32-
virtual int foo() = 0;
33-
};
34-
35-
class Interface_B {
36-
public:
37-
virtual int bar() = 0;
38-
};
39-
40-
// No warning
41-
class Good_Child1 : public Interface_A, Interface_B {
42-
virtual int foo() override { return 0; }
43-
virtual int bar() override { return 0; }
44-
};
45-
46-
See the features disallowed in Fuchsia at https://fuchsia.dev/fuchsia-src/development/languages/c-cpp/cxx?hl=en
9+
See the features disallowed in Fuchsia at https://fuchsia.dev/fuchsia-src/development/languages/c-cpp/cxx?hl=en

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ Clang-Tidy Checks
222222
:doc:`darwin-dispatch-once-nonstatic <darwin/dispatch-once-nonstatic>`, "Yes"
223223
:doc:`fuchsia-default-arguments-calls <fuchsia/default-arguments-calls>`,
224224
:doc:`fuchsia-default-arguments-declarations <fuchsia/default-arguments-declarations>`, "Yes"
225-
:doc:`fuchsia-multiple-inheritance <fuchsia/multiple-inheritance>`,
226225
:doc:`fuchsia-overloaded-operator <fuchsia/overloaded-operator>`,
227226
:doc:`fuchsia-statically-constructed-objects <fuchsia/statically-constructed-objects>`,
228227
:doc:`fuchsia-temporary-objects <fuchsia/temporary-objects>`,
@@ -272,6 +271,7 @@ Clang-Tidy Checks
272271
:doc:`misc-misleading-bidirectional <misc/misleading-bidirectional>`,
273272
:doc:`misc-misleading-identifier <misc/misleading-identifier>`,
274273
:doc:`misc-misplaced-const <misc/misplaced-const>`,
274+
:doc:`misc-multiple-inheritance <misc/multiple-inheritance>`,
275275
:doc:`misc-new-delete-overloads <misc/new-delete-overloads>`,
276276
:doc:`misc-no-recursion <misc/no-recursion>`,
277277
:doc:`misc-non-copyable-objects <misc/non-copyable-objects>`,
@@ -584,6 +584,7 @@ Check aliases
584584
:doc:`cppcoreguidelines-non-private-member-variables-in-classes <cppcoreguidelines/non-private-member-variables-in-classes>`, :doc:`misc-non-private-member-variables-in-classes <misc/non-private-member-variables-in-classes>`,
585585
:doc:`cppcoreguidelines-use-default-member-init <cppcoreguidelines/use-default-member-init>`, :doc:`modernize-use-default-member-init <modernize/use-default-member-init>`, "Yes"
586586
:doc:`fuchsia-header-anon-namespaces <fuchsia/header-anon-namespaces>`, :doc:`google-build-namespaces <google/build-namespaces>`,
587+
:doc:`fuchsia-multiple-inheritance <fuchsia/multiple-inheritance>`, :doc:`misc-multiple-inheritance <misc/multiple-inheritance>`,
587588
:doc:`google-readability-braces-around-statements <google/readability-braces-around-statements>`, :doc:`readability-braces-around-statements <readability/braces-around-statements>`, "Yes"
588589
:doc:`google-readability-casting <google/readability-casting>`, :doc:`modernize-avoid-c-style-cast <modernize/avoid-c-style-cast>`,
589590
:doc:`google-readability-function-size <google/readability-function-size>`, :doc:`readability-function-size <readability/function-size>`,
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
.. title:: clang-tidy - misc-multiple-inheritance
2+
3+
misc-multiple-inheritance
4+
=========================
5+
6+
Warns if a class inherits from multiple classes that are not pure virtual.
7+
8+
For example, declaring a class that inherits from multiple concrete classes is
9+
disallowed:
10+
11+
.. code-block:: c++
12+
13+
class Base_A {
14+
public:
15+
virtual int foo() { return 0; }
16+
};
17+
18+
class Base_B {
19+
public:
20+
virtual int bar() { return 0; }
21+
};
22+
23+
// Warning
24+
class Bad_Child1 : public Base_A, Base_B {};
25+
26+
A class that inherits from a pure virtual is allowed:
27+
28+
.. code-block:: c++
29+
30+
class Interface_A {
31+
public:
32+
virtual int foo() = 0;
33+
};
34+
35+
class Interface_B {
36+
public:
37+
virtual int bar() = 0;
38+
};
39+
40+
// No warning
41+
class Good_Child1 : public Interface_A, Interface_B {
42+
virtual int foo() override { return 0; }
43+
virtual int bar() override { return 0; }
44+
};
45+
46+
References
47+
----------
48+
49+
See the features disallowed in Fuchsia at https://fuchsia.dev/fuchsia-src/development/languages/c-cpp/cxx?hl=en

0 commit comments

Comments
 (0)