[PATCH] D24339: [clang-tidy] Add check 'readability-redundant-member-init'
Malcolm Parsons via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 8 12:13:47 PDT 2016
malcolm.parsons added a comment.
How do I add FixIt hints?
They should be simple removals, but how do I decide whether to remove the following comma, preceding comma or preceding colon?
================
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();
----------------
sbenza wrote:
> 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.
Yes, more tests needed.
================
Comment at: clang-tidy/readability/RedundantMemberInitCheck.cpp:39
@@ +38,3 @@
+
+ if (std::find_if(begin(arguments), end(arguments), [](const Expr *expr) {
+ return !expr->isDefaultArgument();
----------------
sbenza wrote:
> You want `std::none_of` instead of `std::find_if`.
> (or use `std::any_of` and don't negate the expression in the lambda)
Maybe I only need to check the first argument - if that's defaulted then they all are.
================
Comment at: docs/clang-tidy/checks/readability-redundant-member-init.rst:6
@@ +5,3 @@
+
+Finds unnecessary member initializations.
+
----------------
sbenza wrote:
> Explain when they are unnecessary.
"Finds member initializations that are unnecessary because the same default constructor would be called if they were not present"
Repository:
rL LLVM
https://reviews.llvm.org/D24339
More information about the cfe-commits
mailing list