Skip to content

Commit

Permalink
[clang-tidy] add aliases for hicpp module
Browse files Browse the repository at this point in the history
Summary: Add some hicpp checks that can be implmented as alises for existing clang-tidy checks:
hicpp-explicit-conversions
hicpp-function-size
hicpp-named-parameter
hicpp-invalid-access-moved
hicpp-member-init
hicpp-new-delete-operators
hicpp-noexcept-move
hicpp-special-member-functions
hicpp-undelegated-constructor
hicpp-use-equals-default
hicpp-use-equals-delete
hicpp-use-override

Reviewers: dberlin, jbcoe, aaron.ballman, alexfh

Reviewed By: aaron.ballman

Subscribers: JDevlieghere

Differential Revision: https://reviews.llvm.org/D30383

Patch By: Jonas Toth

llvm-svn: 299068
  • Loading branch information
jbcoe committed Mar 30, 2017
1 parent 7a76b31 commit 8823226
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 5 deletions.
41 changes: 39 additions & 2 deletions clang-tools-extra/clang-tidy/hicpp/HICPPTidyModule.cpp
Expand Up @@ -10,6 +10,19 @@
#include "../ClangTidy.h"
#include "../ClangTidyModule.h"
#include "../ClangTidyModuleRegistry.h"
#include "../cppcoreguidelines/ProTypeMemberInitCheck.h"
#include "../cppcoreguidelines/SpecialMemberFunctionsCheck.h"
#include "../google/DefaultArgumentsCheck.h"
#include "../google/ExplicitConstructorCheck.h"
#include "../misc/NewDeleteOverloadsCheck.h"
#include "../misc/NoexceptMoveConstructorCheck.h"
#include "../misc/UndelegatedConstructor.h"
#include "../misc/UseAfterMoveCheck.h"
#include "../modernize/UseEqualsDefaultCheck.h"
#include "../modernize/UseEqualsDeleteCheck.h"
#include "../modernize/UseOverrideCheck.h"
#include "../readability/FunctionSizeCheck.h"
#include "../readability/IdentifierNamingCheck.h"
#include "NoAssemblerCheck.h"

namespace clang {
Expand All @@ -19,8 +32,32 @@ namespace hicpp {
class HICPPModule : public ClangTidyModule {
public:
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
CheckFactories.registerCheck<NoAssemblerCheck>(
"hicpp-no-assembler");
CheckFactories.registerCheck<google::ExplicitConstructorCheck>(
"hicpp-explicit-conversions");
CheckFactories.registerCheck<readability::FunctionSizeCheck>(
"hicpp-function-size");
CheckFactories.registerCheck<readability::IdentifierNamingCheck>(
"hicpp-named-parameter");
CheckFactories.registerCheck<misc::UseAfterMoveCheck>(
"hicpp-invalid-access-moved");
CheckFactories.registerCheck<cppcoreguidelines::ProTypeMemberInitCheck>(
"hicpp-member-init");
CheckFactories.registerCheck<misc::NewDeleteOverloadsCheck>(
"hicpp-new-delete-operators");
CheckFactories.registerCheck<misc::NoexceptMoveConstructorCheck>(
"hicpp-noexcept-move");
CheckFactories.registerCheck<NoAssemblerCheck>("hicpp-no-assembler");
CheckFactories
.registerCheck<cppcoreguidelines::SpecialMemberFunctionsCheck>(
"hicpp-special-member-functions");
CheckFactories.registerCheck<misc::UndelegatedConstructorCheck>(
"hicpp-undelegated-constructor");
CheckFactories.registerCheck<modernize::UseEqualsDefaultCheck>(
"hicpp-use-equals-default");
CheckFactories.registerCheck<modernize::UseEqualsDeleteCheck>(
"hicpp-use-equals-delete");
CheckFactories.registerCheck<modernize::UseOverrideCheck>(
"hicpp-use-override");
}
};

Expand Down
6 changes: 3 additions & 3 deletions clang-tools-extra/docs/ReleaseNotes.rst
Expand Up @@ -76,10 +76,10 @@ Improvements to clang-tidy

Finds functions that have more then `ParameterThreshold` parameters and emits a warning.

- New `safety-no-assembler
<http://clang.llvm.org/extra/clang-tidy/checks/safety-no-assembler.html>`_ check
- New `hicpp` module

Finds uses of inline assembler.
Adds checks that implement the `High Integrity C++ Coding Standard <http://www.codingstandard.com/section/index/>`_ and other safety
standards. Many checks are aliased to other modules.

- New `modernize-return-braced-init-list
<http://clang.llvm.org/extra/clang-tidy/checks/modernize-return-braced-init-list.html>`_ check
Expand Down
@@ -0,0 +1,15 @@
.. title:: clang-tidy - hicpp-explicit-conversions

hicpp-explicit-conversions
==========================

This check is an alias for `google-explicit-constructor <google-explicit-constructor.hml>`_.
Used to enforce parts of `rule 5.4.1 <http://www.codingstandard.com/rule/5-4-1-only-use-casting-forms-static_cast-excl-void-dynamic_cast-or-explicit-constructor-call/>`_.
This check will enforce that constructors and conversion operators are marked `explicit`.
Other forms of casting checks are implemented in other places.
The following checks can be used to check for more forms of casting:

- `cppcoreguidelines-pro-type-static-cast-downcast <cppcoreguidelines-pro-type-static-cast-downcast.html>`_
- `cppcoreguidelines-pro-type-reinterpret-cast <cppcoreguidelines-pro-type-reinterpret-cast.html>`_
- `cppcoreguidelines-pro-type-const-cast <cppcoreguidelines-pro-type-const-cast.html>`_
- `cppcoreguidelines-pro-type-cstyle-cast <cppcoreguidelines-pro-type-cstyle-cast.html>`_
11 changes: 11 additions & 0 deletions clang-tools-extra/docs/clang-tidy/checks/hicpp-function-size.rst
@@ -0,0 +1,11 @@
.. title:: clang-tidy - hicpp-function-size

hicpp-function-size
===================

This check is an alias for `readability-function-size <readability-function-size.hml>`_.
Useful to enforce multiple sections on function complexity.

- `rule 8.2.2 <http://www.codingstandard.com/rule/8-2-2-do-not-declare-functions-with-an-excessive-number-of-parameters/>`_
- `rule 8.3.1 <http://www.codingstandard.com/rule/8-3-1-do-not-write-functions-with-an-excessive-mccabe-cyclomatic-complexity/>`_
- `rule 8.3.2 <http://www.codingstandard.com/rule/8-3-2-do-not-write-functions-with-a-high-static-program-path-count/>`_
@@ -0,0 +1,8 @@
.. title:: clang-tidy - hicpp-invalid-access-moved

hicpp-invalid-access-moved
==========================

This check is an alias for `misc-use-after-move <misc-use-after-move.hml>`_.

Implements parts of the `rule 8.4.1 <http://www.codingstandard.com/rule/8-4-1-do-not-access-an-invalid-object-or-an-object-with-indeterminate-value/>`_ to check if moved-from objects are accessed.
@@ -0,0 +1,9 @@
.. title:: clang-tidy - hicpp-member-init

hicpp-member-init
=================

This check is an alias for `cppcoreguidelines-pro-type-member-init <cppcoreguidelines-pro-type-member-init.hml>`_.
Implements the check for
`rule 12.4.2 <http://www.codingstandard.com/rule/12-4-2-ensure-that-a-constructor-initializes-explicitly-all-base-classes-and-non-static-data-members/>`_
to initialize class members in the right order.
@@ -0,0 +1,8 @@
.. title:: clang-tidy - hicpp-named-parameter

hicpp-named-parameter
=====================

This check is an alias for `readability-named-parameter <readability-named-parameter.hml>`_.

Implements `rule 8.2.1 <http://www.codingstandard.com/rule/8-2-1-make-parameter-names-absent-or-identical-in-all-declarations/>`_.
@@ -0,0 +1,8 @@
.. title:: clang-tidy - hicpp-new-delete-operators

hicpp-new-delete-operators
==========================

This check is an alias for `misc-new-delete-overloads <misc-new-delete-overloads.hml>`_.
Implements `rule 12.3.1 <http://www.codingstandard.com/section/12-3-free-store/>`_ to ensure
the `new` and `delete` operators have the correct signature.
@@ -0,0 +1,7 @@
.. title:: clang-tidy - hicpp-noexcept-move

hicpp-noexcept-move
===================

This check is an alias for `misc-noexcept-moveconstructor <misc-noexcept-moveconstructor.hml>`_.
Checks `rule 12.5.4 <http://www.codingstandard.com/rule/12-5-4-declare-noexcept-the-move-constructor-and-move-assignment-operator/`_ to mark move assignment and move construction `noexcept`.
@@ -0,0 +1,7 @@
.. title:: clang-tidy - hicpp-special-member-functions

hicpp-special-member-functions
==============================

This check is an alias for `cppcoreguidelines-special-member-functions <cppcoreguidelines-special-member-functions.hml>`_.
Checks that special member functions have the correct signature, according to `rule 12.5.7 <http://www.codingstandard.com/rule/12-5-7-declare-assignment-operators-with-the-ref-qualifier/>`_.
@@ -0,0 +1,23 @@
.. title:: clang-tidy - hicpp-undelegated-construtor

hicpp-undelegated-constructor
=============================

This check is an alias for `misc-undelegated-constructor <misc-undelegated-constructor.hml>`_.
Partially implements `rule 12.4.5 <http://www.codingstandard.com/rule/12-4-5-use-delegating-constructors-to-reduce-code-duplication/>`_
to find misplaced constructor calls inside a constructor.

.. code-block:: c++

struct Ctor {
Ctor();
Ctor(int);
Ctor(int, int);
Ctor(Ctor *i) {
// All Ctor() calls result in a temporary object
Ctor(); // did you intend to call a delegated constructor?
Ctor(0); // did you intend to call a delegated constructor?
Ctor(1, 2); // did you intend to call a delegated constructor?
foo();
}
};
@@ -0,0 +1,7 @@
.. title:: clang-tidy - hicpp-use-equals-defaults

hicpp-use-equals-default
========================

This check is an alias for `modernize-use-equals-default <modernize-use-equals-default.hml>`_.
Implements `rule 12.5.1 <http://www.codingstandard.com/rule/12-5-1-define-explicitly-default-or-delete-implicit-special-member-functions-of-concrete-classes/>`_ to explicitly default special member functions.
@@ -0,0 +1,8 @@
.. title:: clang-tidy - hicpp-use-equals-delete

hicpp-use-equals-delete
=======================

This check is an alias for `modernize-use-equals-delete <modernize-use-equals-delete.hml>`_.
Implements `rule 12.5.1 <http://www.codingstandard.com/rule/12-5-1-define-explicitly-default-or-delete-implicit-special-member-functions-of-concrete-classes/>`_
to explicitly default or delete special member functions.
@@ -0,0 +1,8 @@
.. title:: clang-tidy - hicpp-use-override

hicpp-use-override
==================

This check is an alias for `modernize-use-override <modernize-use-override.hml>`_.
Implements `rule 10.2.1 <http://www.codingstandard.com/section/10-2-virtual-functions/>`_ to
declare a virtual function `override` when overriding.

0 comments on commit 8823226

Please sign in to comment.