[PATCH] D104112: [clang-tidy] cppcoreguidelines-avoid-init-default-constructors: a new check

Fabian Thurnheer via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 11 05:02:20 PDT 2021


DNS320 created this revision.
DNS320 added reviewers: aaron.ballman, njames93, alexfh.
DNS320 added a project: clang-tools-extra.
Herald added subscribers: shchenz, kbarton, xazax.hun, mgorny, nemanjai.
DNS320 requested review of this revision.
Herald added a subscriber: cfe-commits.

This check tries to implement C.45 <https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rc-default> 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?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104112

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidInitDefaultConstructorsCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidInitDefaultConstructorsCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-avoid-init-default-constructors.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-init-default-constructors.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104112.351405.patch
Type: text/x-patch
Size: 9983 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210611/306e00d8/attachment.bin>


More information about the cfe-commits mailing list