The check emits a warning if a member-initializer calls the member's default constructor with no arguments.
Details
Diff Detail
- Repository
- rL LLVM
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 | ||
---|---|---|
4 ↗ | (On Diff #70684) | This line length should be same as header above. |
13 ↗ | (On Diff #70684) | Please run Clang-format over example. Will be good idea to add empty line before private. |
test/clang-tidy/readability-redundant-member-init.cpp | ||
33 ↗ | (On Diff #70684) | Please remove extra empty-line. |
clang-tidy/readability/RedundantMemberInitCheck.cpp | ||
---|---|---|
34 ↗ | (On Diff #70684) | Arguments (upper case) |
clang-tidy/readability/RedundantMemberInitCheck.cpp | ||
---|---|---|
36 ↗ | (On Diff #70684) | begin() and end() are not used extensively. Why not to use std::? |
clang-tidy/readability/RedundantMemberInitCheck.cpp | ||
---|---|---|
33 ↗ | (On Diff #70684) | 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. |
34 ↗ | (On Diff #70684) | Arguments variable name. (should start with upper case) |
36 ↗ | (On Diff #70684) | There's no need for these using declarations. |
39 ↗ | (On Diff #70684) | You want std::none_of instead of std::find_if. |
docs/clang-tidy/checks/readability-redundant-member-init.rst | ||
6 ↗ | (On Diff #70684) | Explain when they are unnecessary. |
clang-tidy/readability/RedundantMemberInitCheck.cpp | ||
---|---|---|
34 ↗ | (On Diff #70684) | Please do not use auto here, since the type is not spelled out in the initializer. |
clang-tidy/readability/RedundantMemberInitCheck.h | ||
19 ↗ | (On Diff #70684) | What makes one unnecessary? Also, missing a full stop at the end of the sentence. |
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 | ||
---|---|---|
33 ↗ | (On Diff #70684) | Yes, more tests needed. |
39 ↗ | (On Diff #70684) | 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 | ||
6 ↗ | (On Diff #70684) | "Finds member initializations that are unnecessary because the same default constructor would be called if they were not present" |
clang-tidy/readability/RedundantMemberInitCheck.cpp | ||
---|---|---|
34 ↗ | (On Diff #70797) | 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 ↗ | (On Diff #73260) | Missing a test for union member initializers. Also, a test that multiple inheritance doesn't cause a fixit malfunction would be nice. |