Skip to content

Draft: clang-tidy: Add checks related to the default initialization of class ctors, dtors and variables

Add and apply multiple clang-tidy rules related to the default initialization of class constructors, destructors and member variables. Each rule is described below.

Clang-tidy checks

modernize-use-equals-default

clang-tidy: modernize-use-equals-default.

This rule marks trivial constructors, destructors and copy constructors with = default specifier, indicating to the compiler that they are trivial. This allows further optimizations, as indicated in the reference above.

cppcoreguidelines-prefer-member-initializer

clang-tidy: cppcoreguidelines-prefer-member-initializer.

This check detects cases of class member variables being initialized in the constructor's body, instead of in the constructor's initialization list, which is the recommended method.

readability-redundant-member-init

clang-tidy: readability-redundant-member-init.

This check detects cases of unnecessary class member default initialization.

modernize-use-default-member-init

Add and apply clang-tidy check modernize-use-default-member-init.

This check detects cases of class member variables that are initialized with default values in the constructor's initialization list, instead of next to the corresponding variable declaration. Please refer to the updated section of the file coding-style.rst in this MR for more details.

To Do

  • Add check readability-redundant-string-init.
  • Apply clang-tidy checks.
  • Move the = default from the *.cc file to the .h for additional performance gains.
  • Review coding-style.rst documentation.
Edited by Eduardo Almeida

Merge request reports