The check emits a warning if a member-initializer calls the member's default constructor with no arguments.
Details
Diff Detail
- Build Status
Buildable 70 Build 70: arc lint + arc unit
Event Timeline
I think will be good idea to add cases when member is initialized in declaration and constructor, with same and different values.
docs/clang-tidy/checks/readability-redundant-member-init.rst | ||
---|---|---|
5 | This line length should be same as header above. | |
14 | Please run Clang-format over example. Will be good idea to add empty line before private. | |
test/clang-tidy/readability-redundant-member-init.cpp | ||
34 | Please remove extra empty-line. |
clang-tidy/readability/RedundantMemberInitCheck.cpp | ||
---|---|---|
35 | Arguments (upper case) |
clang-tidy/readability/RedundantMemberInitCheck.cpp | ||
---|---|---|
37 | begin() and end() are not used extensively. Why not to use std::? |
clang-tidy/readability/RedundantMemberInitCheck.cpp | ||
---|---|---|
34 | These construct expressions might actually have side effects that you would not get if you omit them. 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. | |
35 | Arguments variable name. (should start with upper case) | |
37 | There's no need for these using declarations. | |
40 | You want std::none_of instead of std::find_if. | |
docs/clang-tidy/checks/readability-redundant-member-init.rst | ||
7 | Explain when they are unnecessary. |
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?
clang-tidy/readability/RedundantMemberInitCheck.cpp | ||
---|---|---|
34 | Yes, more tests needed. | |
40 | Maybe I only need to check the first argument - if that's defaulted then they all are. | |
docs/clang-tidy/checks/readability-redundant-member-init.rst | ||
7 | "Finds member initializations that are unnecessary because the same default constructor would be called if they were not present" |
clang-tidy/readability/RedundantMemberInitCheck.cpp | ||
---|---|---|
35 | Other forms of initialization are not CXXConstructExprs. |
Just remove the entry and leave the comma and the colon alone. Clang-tidy needs to learn to clean up the code after such replacements using clang-format's cleanupAroundReplacements. Filed https://llvm.org/bugs/show_bug.cgi?id=30379
Don't remove init of const members.
Do remove calls to constructors that introduce cleanups.
test/clang-tidy/readability-redundant-member-init.cpp | ||
---|---|---|
162 | Missing a test for union member initializers. Also, a test that multiple inheritance doesn't cause a fixit malfunction would be nice. |
What makes one unnecessary? Also, missing a full stop at the end of the sentence.