Skip to content

STYLE: Clang tidy cleanups#1628

Merged
hjmjohnson merged 15 commits intoInsightSoftwareConsortium:masterfrom
hjmjohnson:clang-tidy-cleanups
Feb 20, 2020
Merged

STYLE: Clang tidy cleanups#1628
hjmjohnson merged 15 commits intoInsightSoftwareConsortium:masterfrom
hjmjohnson:clang-tidy-cleanups

Conversation

@hjmjohnson
Copy link
Copy Markdown
Member

More clang-tidy identified cleanups found when building with remote modules.

Copy link
Copy Markdown
Member

@dzenanz dzenanz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suggestions about parameter renaming are optional.

Comment thread Modules/IO/Bruker/include/itkBruker2dseqImageIO.h
Comment thread Modules/IO/CSV/include/itkCSVFileReaderBase.h
Comment thread Modules/IO/ImageBase/include/itkImageIOBase.h
Comment thread Modules/Numerics/FEM/include/itkFEMLinearSystemWrapperDenseVNL.h Outdated
Comment thread Modules/Core/Common/include/itkThreadSupport.h Outdated
@hjmjohnson hjmjohnson changed the title Clang tidy cleanups WIP: Clang tidy cleanups Feb 18, 2020
Comment thread Modules/Core/Common/test/itkSmartPointerGTest.cxx
@hjmjohnson hjmjohnson changed the title WIP: Clang tidy cleanups STYLE: Clang tidy cleanups Feb 19, 2020
@hjmjohnson hjmjohnson force-pushed the clang-tidy-cleanups branch 3 times, most recently from 2edeece to bf61ec3 Compare February 19, 2020 21:09
No conditional building needed now that VXL is updated
to a supported version.
Find and remove redundant void argument lists.
Describe function overrides using the override
keyword from C++11.

SRCDIR= #My local SRC
BLDDIR= #My local BLD

cd
run-clang-tidy.py -extra-arg=-D__clang__ -checks=-*,modernize-use-override  -header-filter=.* -fix
Finds and replaces integer literals which are cast to bool.

SRCDIR= #My local SRC
BLDDIR= #My local BLD

cd
run-clang-tidy.py -extra-arg=-D__clang__ -checks=-*,modernize-use-bool-literals  -header-filter=.* -fix
The check flags insertions to an STL-style container done by calling the
push_back method with an explicitly-constructed temporary of the container
element type. In this case, the corresponding emplace_back method results in
less verbose and potentially more efficient code.
The check converts the usage of typedef with using keyword.
Converts a default constructor’s member initializers into the new
default member initializers in C++11. Other member initializers that match the
default member initializer are removed. This can reduce repeated code or allow
use of ‘= default’.
This check replaces default bodies of special member functions with
= default;. The explicitly defaulted function declarations enable more
opportunities in optimization, because the compiler might treat
explicitly defaulted functions as trivial.

Additionally, the C++11 use of = default more clearly expreses the
intent for the special member functions.
This check replaces undefined special member functions with
= delete;. The explicitly deleted function declarations enable more
opportunities in optimization, because the compiler might treat
explicitly delted functions as noops.

Additionally, the C++11 use of = delete more clearly expreses the
intent for the special member functions.
With move semantics added to the language and the standard library updated with
move constructors added for many types it is now interesting to take an
argument directly by value, instead of by const-reference, and then copy. This
check allows the compiler to take care of choosing the best way to construct
the copy.

The transformation is usually beneficial when the calling code passes an rvalue
and assumes the move construction is a cheap operation. This short example
illustrates how the construction of the value happens:

SRCDIR= #My local SRC
BLDDIR= #My local BLD

cd
run-clang-tidy.py -extra-arg=-D__clang__ -checks=-*,modernize-pass-by-value  -header-filter=.* -fix
The emptiness of a container should be checked using the empty() method
instead of the size() method. It is not guaranteed that size() is a
constant-time function, and it is generally more efficient and also
shows clearer intent to use empty(). Furthermore some containers may
implement the empty() method but not implement the size() method. Using
empty() whenever possible makes it easier to switch to another container
in the future.

SRCDIR= #My local SRC
BLDDIR= #My local BLD

cd
run-clang-tidy.py -extra-arg=-D__clang__ -checks=-*,readability-container-size-empty  -header-filter=.* -fix
C++11 Range based for loops can be used in

Used as a more readable equivalent to the traditional for loop operating over a
range of values, such as all elements in a container, in the forward direction..

Range based loopes are more explicit for only computing the
end location once for containers.
… expression

This check is responsible for using the auto type specifier for variable
declarations to improve code readability and maintainability.

The auto type specifier will only be introduced in situations where the
variable type matches the type of the initializer expression. In other words
auto should deduce the same type that was originally spelled in the source
Finds non-static member functions that can be made const because the functions
don’t use this in a non-const way.

This check tries to annotate methods according to logical constness (not
physical constness). Therefore, it will suggest to add a const qualifier to a
non-const method only if this method does something that is already possible
though the public interface on a const pointer to the object:

reading a public member variable calling a public const-qualified member
function returning const-qualified this passing const-qualified this as a
parameter.  This check will also suggest to add a const qualifier to a
non-const method if this method uses private data and functions in a limited
number of ways where logical constness and physical constness coincide:
 - reading a member variable of builtin type
Specifically, this check will not suggest to add a const to a non-const
method if the method reads a private member variable of pointer type because
that allows to modify the pointee which might not preserve logical constness.
For the same reason, it does not allow to call private member functions or
member functions on private member variables.

In addition, this check ignores functions that
 - are declared virtual
 - contain a const_cast
 - are templated or part of a class template
 - have an empty body
 - do not (implicitly) use this at all (see readability-convert-member-functions-to-static).
@hjmjohnson hjmjohnson merged commit abefef1 into InsightSoftwareConsortium:master Feb 20, 2020
N-Dekker added a commit to N-Dekker/ITKSoftwareGuide that referenced this pull request Dec 26, 2021
Following ITK commits:

"STYLE: removing void if used in place of empty parameter list"
by Dženan Zukić, 11 September 2018
InsightSoftwareConsortium/ITK@60807f4

"STYLE: Remove redundant void argument lists"
by Hans Johnson, 20 February 2020
pull request InsightSoftwareConsortium/ITK#1628
InsightSoftwareConsortium/ITK@e6d859e

In accordance with C++ Core Guidelines, August 19, 2021:
"Don't use void as an argument type"
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#nl25-dont-use-void-as-an-argument-type

Clang-Tidy "modernize-redundant-void-arg" check:
https://clang.llvm.org/extra/clang-tidy/checks/modernize-redundant-void-arg.html
dzenanz pushed a commit to InsightSoftwareConsortium/ITKSoftwareGuide that referenced this pull request Dec 27, 2021
Following ITK commits:

"STYLE: removing void if used in place of empty parameter list"
by Dženan Zukić, 11 September 2018
InsightSoftwareConsortium/ITK@60807f4

"STYLE: Remove redundant void argument lists"
by Hans Johnson, 20 February 2020
pull request InsightSoftwareConsortium/ITK#1628
InsightSoftwareConsortium/ITK@e6d859e

In accordance with C++ Core Guidelines, August 19, 2021:
"Don't use void as an argument type"
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#nl25-dont-use-void-as-an-argument-type

Clang-Tidy "modernize-redundant-void-arg" check:
https://clang.llvm.org/extra/clang-tidy/checks/modernize-redundant-void-arg.html
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request Dec 27, 2021
Following ITK commit "STYLE: removing void if used in place of empty parameter list", by Dženan Zukić, 11 September 2018
InsightSoftwareConsortium/ITK@60807f4

And ITK commit "STYLE: Remove redundant void argument lists", by Hans Johnson, 20 February 2020
pull request InsightSoftwareConsortium/ITK#1628
InsightSoftwareConsortium/ITK@e6d859e

In accordance with C++ Core Guidelines, August 19, 2021: "Don't use void as an argument type"
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#nl25-dont-use-void-as-an-argument-type

Clang-Tidy "modernize-redundant-void-arg" check:
https://clang.llvm.org/extra/clang-tidy/checks/modernize-redundant-void-arg.html
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request Dec 27, 2021
Following ITK commit "STYLE: removing void if used in place of empty parameter list", by Dženan Zukić, 11 September 2018
InsightSoftwareConsortium/ITK@60807f4

And ITK commit "STYLE: Remove redundant void argument lists", by Hans Johnson, 20 February 2020
pull request InsightSoftwareConsortium/ITK#1628
InsightSoftwareConsortium/ITK@e6d859e

In accordance with C++ Core Guidelines, August 19, 2021: "Don't use void as an argument type"
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#nl25-dont-use-void-as-an-argument-type

Clang-Tidy "modernize-redundant-void-arg" check:
https://clang.llvm.org/extra/clang-tidy/checks/modernize-redundant-void-arg.html

Using Notepad++ v8.1.9.2, Find in Files (Filters: *.hxx;*.h;*.cxx [v] Match case):

    Find what: (void);
    Replace with: ();
    (*) Normal

    Find what: ( void )
    Replace with: ()
    (*) Normal

    Find what: (void)
    Replace with: ()
    (*) Normal

	Find what:   void)
    Replace with:   )
    (*) Normal

    Find what: (void)\r\n
    Replace with: ()\r\n
    (*) Extended
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Dec 29, 2021
Follow-up to:

"STYLE: removing void if used in place of empty parameter list"
by Dženan Zukić, 11 September 2018
InsightSoftwareConsortium@60807f4

"STYLE: Remove redundant void argument lists"
by Hans Johnson, 20 February 2020
pull request InsightSoftwareConsortium#1628
InsightSoftwareConsortium@e6d859e
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Dec 29, 2021
Did check all itk*.cxx, itk*.h, and itk*.hxx source files.

Follow-up to:

"STYLE: removing void if used in place of empty parameter list"
by Dženan Zukić, 11 September 2018
InsightSoftwareConsortium@60807f4

"STYLE: Remove redundant void argument lists"
by Hans Johnson, 20 February 2020
pull request InsightSoftwareConsortium#1628
InsightSoftwareConsortium@e6d859e
dzenanz pushed a commit that referenced this pull request Dec 30, 2021
Did check all itk*.cxx, itk*.h, and itk*.hxx source files.

Follow-up to:

"STYLE: removing void if used in place of empty parameter list"
by Dženan Zukić, 11 September 2018
60807f4

"STYLE: Remove redundant void argument lists"
by Hans Johnson, 20 February 2020
pull request #1628
e6d859e
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request Dec 30, 2021
Following ITK commit "STYLE: removing void if used in place of empty parameter list", by Dženan Zukić, 11 September 2018
InsightSoftwareConsortium/ITK@60807f4

And ITK commit "STYLE: Remove redundant void argument lists", by Hans Johnson, 20 February 2020
pull request InsightSoftwareConsortium/ITK#1628
InsightSoftwareConsortium/ITK@e6d859e

In accordance with C++ Core Guidelines, August 19, 2021: "Don't use void as an argument type"
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#nl25-dont-use-void-as-an-argument-type

Clang-Tidy "modernize-redundant-void-arg" check:
https://clang.llvm.org/extra/clang-tidy/checks/modernize-redundant-void-arg.html

Using Notepad++ v8.1.9.2, Find in Files (Filters: *.hxx;*.h;*.cxx [v] Match case):

    Find what: (void);
    Replace with: ();
    (*) Normal

    Find what: ( void )
    Replace with: ()
    (*) Normal

    Find what: (void)
    Replace with: ()
    (*) Normal

	Find what:   void)
    Replace with:   )
    (*) Normal

    Find what: (void)\r\n
    Replace with: ()\r\n
    (*) Extended
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request Dec 31, 2021
Following ITK commit "STYLE: removing void if used in place of empty parameter list", by Dženan Zukić, 11 September 2018
InsightSoftwareConsortium/ITK@60807f4

And ITK commit "STYLE: Remove redundant void argument lists", by Hans Johnson, 20 February 2020
pull request InsightSoftwareConsortium/ITK#1628
InsightSoftwareConsortium/ITK@e6d859e

In accordance with C++ Core Guidelines, August 19, 2021: "Don't use void as an argument type"
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#nl25-dont-use-void-as-an-argument-type

Clang-Tidy "modernize-redundant-void-arg" check:
https://clang.llvm.org/extra/clang-tidy/checks/modernize-redundant-void-arg.html

Using Notepad++ v8.1.9.2, Find in Files (Filters: *.hxx;*.h;*.cxx [v] Match case):

    Find what: (void);
    Replace with: ();
    (*) Normal

    Find what: ( void )
    Replace with: ()
    (*) Normal

    Find what: (void)
    Replace with: ()
    (*) Normal

    Find what:   void)
    Replace with:   )
    (*) Normal

    Find what: (void)\r\n
    Replace with: ()\r\n
    (*) Extended
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request Jan 3, 2022
Following ITK commit "STYLE: removing void if used in place of empty parameter list", by Dženan Zukić, 11 September 2018
InsightSoftwareConsortium/ITK@60807f4

And ITK commit "STYLE: Remove redundant void argument lists", by Hans Johnson, 20 February 2020
pull request InsightSoftwareConsortium/ITK#1628
InsightSoftwareConsortium/ITK@e6d859e

In accordance with C++ Core Guidelines, August 19, 2021: "Don't use void as an argument type"
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#nl25-dont-use-void-as-an-argument-type

Clang-Tidy "modernize-redundant-void-arg" check:
https://clang.llvm.org/extra/clang-tidy/checks/modernize-redundant-void-arg.html

Using Notepad++ v8.1.9.2, Find in Files (Filters: *.hxx;*.h;*.cxx [v] Match case):

    Find what: (void);
    Replace with: ();
    (*) Normal

    Find what: ( void )
    Replace with: ()
    (*) Normal

    Find what: (void)
    Replace with: ()
    (*) Normal

    Find what:   void)
    Replace with:   )
    (*) Normal

    Find what: (void)\r\n
    Replace with: ()\r\n
    (*) Extended
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request Jan 5, 2022
Ran LLVM 13.0.0 Clang-Tidy check `modernize-use-using`: https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-using.html

Did Notepad++ v8.1.9.3 Find in Files

    Find what:   typedef (\w+) [ ]*(\w+);
    Replace with:   using $2 = $1;
    [v] Match case
    (*) Regular expression

Following ITK "STYLE: Prefer c++11 'using' to 'typedef'":
- pull request InsightSoftwareConsortium/ITK#1628 commit InsightSoftwareConsortium/ITK@32f6f1e by Hans Johnson, 20 February 2020.
- pull request InsightSoftwareConsortium/ITK#1047 commit InsightSoftwareConsortium/ITK@f42f88b by Hans Johnson, Dženan Zukić, 1 July 2019

In accordance with C++ Core Guidelines, January 3, 2022: "Prefer `using` over `typedef` for defining aliases", https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rt-using
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants