[PATCH] D24339: [clang-tidy] Add check 'readability-redundant-member-init'

Samuel Benzaquen via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 8 11:44:15 PDT 2016


sbenza added inline comments.

================
Comment at: clang-tidy/readability/RedundantMemberInitCheck.cpp:33
@@ +32,3 @@
+  const auto *Init = Result.Nodes.getNodeAs<CXXCtorInitializer>("init");
+  const auto *Construct = Result.Nodes.getNodeAs<CXXConstructExpr>("construct");
+  const auto arguments = Construct->arguments();
----------------
These construct expressions might actually have side effects that you would not get if you omit them.
For example, aggregates will be value initialized. If you remove it you change the behavior.

The tests should include defaulted vs non-defaulted default constructor, user-defined/user-provided/implicit default constructor, aggregates with and without trivially constructible members, etc.

================
Comment at: clang-tidy/readability/RedundantMemberInitCheck.cpp:34
@@ +33,3 @@
+  const auto *Construct = Result.Nodes.getNodeAs<CXXConstructExpr>("construct");
+  const auto arguments = Construct->arguments();
+
----------------
Prazek wrote:
> Arguments (upper case)
Arguments variable name. (should start with upper case)

================
Comment at: clang-tidy/readability/RedundantMemberInitCheck.cpp:36
@@ +35,3 @@
+
+  using std::begin;
+  using std::end;
----------------
There's no need for these using declarations.
Just do arguments.begin()/arguments.end().
They are using in generic code. This is not generic code.

================
Comment at: clang-tidy/readability/RedundantMemberInitCheck.cpp:39
@@ +38,3 @@
+
+  if (std::find_if(begin(arguments), end(arguments), [](const Expr *expr) {
+        return !expr->isDefaultArgument();
----------------
You want `std::none_of` instead of `std::find_if`.
(or use `std::any_of` and don't negate the expression in the lambda)

================
Comment at: docs/clang-tidy/checks/readability-redundant-member-init.rst:6
@@ +5,3 @@
+
+Finds unnecessary member initializations.                                                                               
+                                                                                                                        
----------------
Explain when they are unnecessary.


Repository:
  rL LLVM

https://reviews.llvm.org/D24339





More information about the cfe-commits mailing list