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

Balogh, Ádám via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 26 01:35:14 PDT 2020


baloghadamsoftware marked 7 inline comments as done.
baloghadamsoftware added inline comments.


================
Comment at: clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp:126-128
+  const auto *Body = dyn_cast_or_null<CompoundStmt>(Ctor->getBody());
+  if (!Body)
+    return;
----------------
aaron.ballman wrote:
> This can be hoisted into the matcher with `hasBody(anything())` I believe. One interesting test case that's somewhat related are constructors that use a function-try-block instead of a compound statement. e.g.,
> ```
> class C {
>   int i;
> 
> public:
>   C() try {
>     i = 12;
>   } catch (...) {
>   }
> };
> ```
I think we should skip these cases similarly to initialization inside a try block in a body that is compound statement. Maybe the initialization throws thus it is inappropriate to convert it to member initializer. I also added a test case for this.


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

https://reviews.llvm.org/D71199





More information about the cfe-commits mailing list