Page MenuHomePhabricator

[clang-tidy] cppcoreguidelines-avoid-init-default-constructors: a new check
Needs ReviewPublic

Authored by DNS320 on Jun 11 2021, 5:02 AM.

Details

Summary

This check tries to implement C.45 of the C++ Core Guidelines.
During the implementation of the current state of this check, it was found that multiple functionalities, which the check also could use, already exists in other clang-tidy checks. These are:

  • Lookup if the body of a constructor (only) initialize class members (cppcoreguidelines-prefer-member-initializer)
  • Set a constructor =default if possible (hicpp-use-equals-default)
  • If possible, move/change constructor list initializers to class member initializers (modernize-use-default-member-init)

I would like to ask how I could proceed, as reimplementing already existing functionality of other checks might not be preferred, because of reasons like duplication and maintainability. But I think it would be beneficial if a check exists that combines the mentioned functionalities under the cppcoreguidelines module.

Generally, do you see a need for this check at all or is the activation of the three checks mentioned above the way to go to implicitly enforce C.45?

Diff Detail

Event Timeline

DNS320 created this revision.Jun 11 2021, 5:02 AM
DNS320 requested review of this revision.Jun 11 2021, 5:02 AM
Eugene.Zelenko added inline comments.
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidInitDefaultConstructorsCheck.h
28

Shouldn't this check be enabled in C++11 or newer?

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-avoid-init-default-constructors.rst
6

Please synchronize this statement with Release Notes.

What about bit filed members - their initialization is supported only in C++20.