[PATCH] D71199: [clang-tidy] New check readability-prefer-initialization-list
Whisperity via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 9 05:45:13 PST 2019
whisperity added a comment.
Can you refresh my memory on whether a rule for "if init expr is constant, initialise in class body instead" exists for init list members? If so, this will be a funny "two pass needed to fix" kind of check.
================
Comment at: clang-tools-extra/clang-tidy/readability/PreferInitializationListCheck.cpp:19
+
+static bool isControlStatement(const Stmt *S) {
+ return isa<IfStmt>(S) ||
----------------
I'm working on a checker which has the need for similarly knowing occurrences of "control flow breaking statements". How about `goto` and calling a `[[noreturn]]` function, such as (`std::`)`longjmp`? Or there is no point in matching such in your checker?
================
Comment at: clang-tools-extra/clang-tidy/readability/PreferInitializationListCheck.cpp:71
+ const MatchFinder::MatchResult &Result) {
+ // FIXME: Add callback implementation.
+ const auto *Ctor = Result.Nodes.getNodeAs<CXXConstructorDecl>("ctor");
----------------
FIXME remained. Did you upload the right patch set?
================
Comment at: clang-tools-extra/clang-tidy/readability/PreferInitializationListCheck.cpp:85
+ if (const NamedDecl* Mbr = isAssignmentToMemberOf(Class, S)) {
+ diag(S->getBeginLoc(), "%0 can be initialized in the initializer list"
+ " of the constructor") << Mbr->getName();
----------------
can -> should?
================
Comment at: clang-tools-extra/clang-tidy/readability/PreferInitializationListCheck.h:18
+
+/// FIXME: Write a short description.
+///
----------------
FIXME remained here.
================
Comment at: clang-tools-extra/docs/clang-tidy/checks/readability-prefer-initialization-list.rst:7
+Finds member initializations in the constructor body which can be placed into
+the initialization list instead. This does not only improves the readability of
+the code but also affects positively its performance. Class-member assignments
----------------
improves -> improve
================
Comment at: clang-tools-extra/docs/clang-tidy/checks/readability-prefer-initialization-list.rst:8
+the initialization list instead. This does not only improves the readability of
+the code but also affects positively its performance. Class-member assignments
+inside a control statement or following the first control statement are ignored.
----------------
word order: also positively affects
================
Comment at: clang-tools-extra/docs/clang-tidy/checks/readability-prefer-initialization-list.rst:27
+
+Here ``n`` can be initialized in the construcotr list, but ``m`` not, because
+its initialization follow a control statement (``if``):
----------------
typo: construcotr
================
Comment at: clang-tools-extra/docs/clang-tidy/checks/readability-prefer-initialization-list.rst:27-28
+
+Here ``n`` can be initialized in the construcotr list, but ``m`` not, because
+its initialization follow a control statement (``if``):
+
----------------
whisperity wrote:
> typo: construcotr
[l]ist, unlike `m`, as `m`'s initialization follow a control statement (`if`)
Repository:
rCTE Clang Tools Extra
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D71199/new/
https://reviews.llvm.org/D71199
More information about the cfe-commits
mailing list