[PATCH] D71199: [clang-tidy] New check cppcoreguidelines-prefer-member-initializer

Nathan James via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 20 18:33:28 PST 2021


njames93 added inline comments.
Herald added a subscriber: shchenz.


================
Comment at: clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp:184
+        bool AddComma = false;
+        if (!Ctor->getNumCtorInitializers() && FirstToCtorInits) {
+          SourceLocation BodyPos = Ctor->getBody()->getBeginLoc();
----------------
Rechi wrote:
> The following example generates invalid fixes, if modernize-use-default-member-init check isn't enabled, because `Ctor->getNumCtorInitializers()` returns 1.
> 
> ```lang=cpp
> class Example
> {
> public:
>   Example() { a = 0; };
>   int a;
>   std::string string;
> };
> ```
I've done a little work trying to fix some issues I've noticed while running this check in the wild. I have a feeling this shortcoming has been addressed in there - D97132.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71199/new/

https://reviews.llvm.org/D71199



More information about the cfe-commits mailing list