diff --git a/clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt b/clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt index c7234098f094a..dfd23c3bb48b0 100644 --- a/clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt @@ -7,7 +7,6 @@ add_clang_library(clangTidyFuchsiaModule STATIC DefaultArgumentsCallsCheck.cpp DefaultArgumentsDeclarationsCheck.cpp FuchsiaTidyModule.cpp - MultipleInheritanceCheck.cpp OverloadedOperatorCheck.cpp StaticallyConstructedObjectsCheck.cpp TemporaryObjectsCheck.cpp @@ -17,6 +16,7 @@ add_clang_library(clangTidyFuchsiaModule STATIC LINK_LIBS clangTidy clangTidyGoogleModule + clangTidyMiscModule clangTidyUtils DEPENDS diff --git a/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp b/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp index c62c43f0c42a3..284f72a8f20fd 100644 --- a/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp @@ -10,9 +10,9 @@ #include "../ClangTidyModule.h" #include "../ClangTidyModuleRegistry.h" #include "../google/UnnamedNamespaceInHeaderCheck.h" +#include "../misc/MultipleInheritanceCheck.h" #include "DefaultArgumentsCallsCheck.h" #include "DefaultArgumentsDeclarationsCheck.h" -#include "MultipleInheritanceCheck.h" #include "OverloadedOperatorCheck.h" #include "StaticallyConstructedObjectsCheck.h" #include "TemporaryObjectsCheck.h" @@ -34,7 +34,7 @@ class FuchsiaModule : public ClangTidyModule { "fuchsia-default-arguments-declarations"); CheckFactories.registerCheck( "fuchsia-header-anon-namespaces"); - CheckFactories.registerCheck( + CheckFactories.registerCheck( "fuchsia-multiple-inheritance"); CheckFactories.registerCheck( "fuchsia-overloaded-operator"); diff --git a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt index e8705aada3f22..86643eb28d65a 100644 --- a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt @@ -28,6 +28,7 @@ add_clang_library(clangTidyMiscModule STATIC MisleadingBidirectionalCheck.cpp MisleadingIdentifierCheck.cpp MisplacedConstCheck.cpp + MultipleInheritanceCheck.cpp NewDeleteOverloadsCheck.cpp NoRecursionCheck.cpp NonCopyableObjectsCheck.cpp diff --git a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp index 03f25775de0bf..36e545e06bb6d 100644 --- a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp @@ -18,6 +18,7 @@ #include "MisleadingBidirectionalCheck.h" #include "MisleadingIdentifierCheck.h" #include "MisplacedConstCheck.h" +#include "MultipleInheritanceCheck.h" #include "NewDeleteOverloadsCheck.h" #include "NoRecursionCheck.h" #include "NonCopyableObjectsCheck.h" @@ -57,6 +58,8 @@ class MiscModule : public ClangTidyModule { CheckFactories.registerCheck( "misc-misleading-identifier"); CheckFactories.registerCheck("misc-misplaced-const"); + CheckFactories.registerCheck( + "misc-multiple-inheritance"); CheckFactories.registerCheck( "misc-new-delete-overloads"); CheckFactories.registerCheck("misc-no-recursion"); diff --git a/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp b/clang-tools-extra/clang-tidy/misc/MultipleInheritanceCheck.cpp similarity index 97% rename from clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp rename to clang-tools-extra/clang-tidy/misc/MultipleInheritanceCheck.cpp index 4a10cb4085a41..557b4559697b9 100644 --- a/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/MultipleInheritanceCheck.cpp @@ -13,7 +13,7 @@ using namespace clang; using namespace clang::ast_matchers; -namespace clang::tidy::fuchsia { +namespace clang::tidy::misc { namespace { AST_MATCHER(CXXRecordDecl, hasBases) { @@ -74,4 +74,4 @@ void MultipleInheritanceCheck::check(const MatchFinder::MatchResult &Result) { "pure virtual is discouraged"); } -} // namespace clang::tidy::fuchsia +} // namespace clang::tidy::misc diff --git a/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.h b/clang-tools-extra/clang-tidy/misc/MultipleInheritanceCheck.h similarity index 77% rename from clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.h rename to clang-tools-extra/clang-tidy/misc/MultipleInheritanceCheck.h index 4dcbd0c7893c5..4b4d715628bfc 100644 --- a/clang-tools-extra/clang-tidy/fuchsia/MultipleInheritanceCheck.h +++ b/clang-tools-extra/clang-tidy/misc/MultipleInheritanceCheck.h @@ -6,17 +6,17 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_MULTIPLEINHERITANCECHECK_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_MULTIPLEINHERITANCECHECK_H +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MULTIPLEINHERITANCECHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MULTIPLEINHERITANCECHECK_H #include "../ClangTidyCheck.h" -namespace clang::tidy::fuchsia { +namespace clang::tidy::misc { /// Multiple implementation inheritance is discouraged. /// /// For the user-facing documentation see: -/// https://clang.llvm.org/extra/clang-tidy/checks/fuchsia/multiple-inheritance.html +/// https://clang.llvm.org/extra/clang-tidy/checks/misc/multiple-inheritance.html class MultipleInheritanceCheck : public ClangTidyCheck { public: MultipleInheritanceCheck(StringRef Name, ClangTidyContext *Context) @@ -38,6 +38,6 @@ class MultipleInheritanceCheck : public ClangTidyCheck { llvm::DenseMap InterfaceMap; }; -} // namespace clang::tidy::fuchsia +} // namespace clang::tidy::misc -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_MULTIPLEINHERITANCECHECK_H +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_MULTIPLEINHERITANCECHECK_H diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 6d3da6183c86a..f855277c7d6e9 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -328,6 +328,11 @@ New check aliases ` keeping initial check as an alias to the new one. +- Renamed :doc:`fuchsia-multiple-inheritance ` to + :doc:`misc-multiple-inheritance + ` + keeping initial check as an alias to the new one. + - Renamed :doc:`google-readability-casting ` to :doc:`modernize-avoid-c-style-cast ` diff --git a/clang-tools-extra/docs/clang-tidy/checks/fuchsia/multiple-inheritance.rst b/clang-tools-extra/docs/clang-tidy/checks/fuchsia/multiple-inheritance.rst index 2f6ed18e82028..85eb504104f6b 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/fuchsia/multiple-inheritance.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/fuchsia/multiple-inheritance.rst @@ -3,44 +3,7 @@ fuchsia-multiple-inheritance ============================ -Warns if a class inherits from multiple classes that are not pure virtual. +The `fuchsia-multiple-inheritance` check is an alias, please See +:doc:`misc-multiple-inheritance <../misc/multiple-inheritance>` for details. -For example, declaring a class that inherits from multiple concrete classes is -disallowed: - -.. code-block:: c++ - - class Base_A { - public: - virtual int foo() { return 0; } - }; - - class Base_B { - public: - virtual int bar() { return 0; } - }; - - // Warning - class Bad_Child1 : public Base_A, Base_B {}; - -A class that inherits from a pure virtual is allowed: - -.. code-block:: c++ - - class Interface_A { - public: - virtual int foo() = 0; - }; - - class Interface_B { - public: - virtual int bar() = 0; - }; - - // No warning - class Good_Child1 : public Interface_A, Interface_B { - virtual int foo() override { return 0; } - virtual int bar() override { return 0; } - }; - -See the features disallowed in Fuchsia at https://fuchsia.dev/fuchsia-src/development/languages/c-cpp/cxx?hl=en +See the features disallowed in Fuchsia at https://fuchsia.dev/fuchsia-src/development/languages/c-cpp/cxx?hl=en \ No newline at end of file diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst index 865a2d34e94c2..e5e77b5cc418b 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/list.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst @@ -222,7 +222,6 @@ Clang-Tidy Checks :doc:`darwin-dispatch-once-nonstatic `, "Yes" :doc:`fuchsia-default-arguments-calls `, :doc:`fuchsia-default-arguments-declarations `, "Yes" - :doc:`fuchsia-multiple-inheritance `, :doc:`fuchsia-overloaded-operator `, :doc:`fuchsia-statically-constructed-objects `, :doc:`fuchsia-temporary-objects `, @@ -272,6 +271,7 @@ Clang-Tidy Checks :doc:`misc-misleading-bidirectional `, :doc:`misc-misleading-identifier `, :doc:`misc-misplaced-const `, + :doc:`misc-multiple-inheritance `, :doc:`misc-new-delete-overloads `, :doc:`misc-no-recursion `, :doc:`misc-non-copyable-objects `, @@ -584,6 +584,7 @@ Check aliases :doc:`cppcoreguidelines-non-private-member-variables-in-classes `, :doc:`misc-non-private-member-variables-in-classes `, :doc:`cppcoreguidelines-use-default-member-init `, :doc:`modernize-use-default-member-init `, "Yes" :doc:`fuchsia-header-anon-namespaces `, :doc:`google-build-namespaces `, + :doc:`fuchsia-multiple-inheritance `, :doc:`misc-multiple-inheritance `, :doc:`google-readability-braces-around-statements `, :doc:`readability-braces-around-statements `, "Yes" :doc:`google-readability-casting `, :doc:`modernize-avoid-c-style-cast `, :doc:`google-readability-function-size `, :doc:`readability-function-size `, diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc/multiple-inheritance.rst b/clang-tools-extra/docs/clang-tidy/checks/misc/multiple-inheritance.rst new file mode 100644 index 0000000000000..8092baf1d6ee5 --- /dev/null +++ b/clang-tools-extra/docs/clang-tidy/checks/misc/multiple-inheritance.rst @@ -0,0 +1,49 @@ +.. title:: clang-tidy - misc-multiple-inheritance + +misc-multiple-inheritance +========================= + +Warns if a class inherits from multiple classes that are not pure virtual. + +For example, declaring a class that inherits from multiple concrete classes is +disallowed: + +.. code-block:: c++ + + class Base_A { + public: + virtual int foo() { return 0; } + }; + + class Base_B { + public: + virtual int bar() { return 0; } + }; + + // Warning + class Bad_Child1 : public Base_A, Base_B {}; + +A class that inherits from a pure virtual is allowed: + +.. code-block:: c++ + + class Interface_A { + public: + virtual int foo() = 0; + }; + + class Interface_B { + public: + virtual int bar() = 0; + }; + + // No warning + class Good_Child1 : public Interface_A, Interface_B { + virtual int foo() override { return 0; } + virtual int bar() override { return 0; } + }; + +References +---------- + +See the features disallowed in Fuchsia at https://fuchsia.dev/fuchsia-src/development/languages/c-cpp/cxx?hl=en diff --git a/clang-tools-extra/test/clang-tidy/checkers/fuchsia/multiple-inheritance.cpp b/clang-tools-extra/test/clang-tidy/checkers/misc/multiple-inheritance.cpp similarity index 86% rename from clang-tools-extra/test/clang-tidy/checkers/fuchsia/multiple-inheritance.cpp rename to clang-tools-extra/test/clang-tidy/checkers/misc/multiple-inheritance.cpp index c60649f52cb94..6004ab3d812ea 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/fuchsia/multiple-inheritance.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/misc/multiple-inheritance.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy %s fuchsia-multiple-inheritance %t +// RUN: %check_clang_tidy %s misc-multiple-inheritance %t class Base_A { public: @@ -45,16 +45,16 @@ class Interface_with_A_Parent : public Base_A { class Bad_Child1; // Inherits from multiple concrete classes. -// CHECK-MESSAGES: [[@LINE+2]]:1: warning: inheriting multiple classes that aren't pure virtual is discouraged [fuchsia-multiple-inheritance] +// CHECK-MESSAGES: [[@LINE+2]]:1: warning: inheriting multiple classes that aren't pure virtual is discouraged [misc-multiple-inheritance] // CHECK-NEXT: class Bad_Child1 : public Base_A, Base_B {}; class Bad_Child1 : public Base_A, Base_B {}; -// CHECK-MESSAGES: [[@LINE+1]]:1: warning: inheriting multiple classes that aren't pure virtual is discouraged [fuchsia-multiple-inheritance] +// CHECK-MESSAGES: [[@LINE+1]]:1: warning: inheriting multiple classes that aren't pure virtual is discouraged [misc-multiple-inheritance] class Bad_Child2 : public Base_A, Interface_A_with_member { virtual int foo() override { return 0; } }; -// CHECK-MESSAGES: [[@LINE+2]]:1: warning: inheriting multiple classes that aren't pure virtual is discouraged [fuchsia-multiple-inheritance] +// CHECK-MESSAGES: [[@LINE+2]]:1: warning: inheriting multiple classes that aren't pure virtual is discouraged [misc-multiple-inheritance] // CHECK-NEXT: class Bad_Child3 : public Interface_with_A_Parent, Base_B { class Bad_Child3 : public Interface_with_A_Parent, Base_B { virtual int baz() override { return 0; } @@ -83,7 +83,7 @@ class Good_Child3 : public Base_A_child, Interface_C, Interface_B { struct B1 { int x; }; struct B2 { int x;}; -// CHECK-MESSAGES: [[@LINE+2]]:1: warning: inheriting multiple classes that aren't pure virtual is discouraged [fuchsia-multiple-inheritance] +// CHECK-MESSAGES: [[@LINE+2]]:1: warning: inheriting multiple classes that aren't pure virtual is discouraged [misc-multiple-inheritance] // CHECK-NEXT: struct D : B1, B2 {}; struct D1 : B1, B2 {}; @@ -100,7 +100,7 @@ struct D3 : V3, V4 {}; struct Base3 {}; struct V5 : virtual Base3 { virtual void f(); }; struct V6 : virtual Base3 { virtual void g(); }; -// CHECK-MESSAGES: [[@LINE+2]]:1: warning: inheriting multiple classes that aren't pure virtual is discouraged [fuchsia-multiple-inheritance] +// CHECK-MESSAGES: [[@LINE+2]]:1: warning: inheriting multiple classes that aren't pure virtual is discouraged [misc-multiple-inheritance] // CHECK-NEXT: struct D4 : V5, V6 {}; struct D4 : V5, V6 {}; @@ -118,7 +118,7 @@ struct Base6 { virtual void f(); }; struct Base7 { virtual void g(); }; struct V15 : virtual Base6 { virtual void f() = 0; }; struct V16 : virtual Base7 { virtual void g() = 0; }; -// CHECK-MESSAGES: [[@LINE+2]]:1: warning: inheriting multiple classes that aren't pure virtual is discouraged [fuchsia-multiple-inheritance] +// CHECK-MESSAGES: [[@LINE+2]]:1: warning: inheriting multiple classes that aren't pure virtual is discouraged [misc-multiple-inheritance] // CHECK-NEXT: struct D9 : V15, V16 {}; struct D9 : V15, V16 {}; @@ -159,7 +159,7 @@ namespace N { struct S1 { int i; }; struct S2 { int i; }; -// CHECK-MESSAGES: [[@LINE+1]]:1: warning: inheriting multiple classes that aren't pure virtual is discouraged [fuchsia-multiple-inheritance] +// CHECK-MESSAGES: [[@LINE+1]]:1: warning: inheriting multiple classes that aren't pure virtual is discouraged [misc-multiple-inheritance] struct S3 : S1, S2 {}; } // namespace N