[PATCH] D18457: [clang-tidy] Add a new checker to detect missing comma in initializer list.

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 29 12:09:52 PDT 2016


alexfh added inline comments.

================
Comment at: clang-tidy/misc/SuspiciousMissingCommaCheck.cpp:42
@@ +41,3 @@
+  const auto *ConcatenatedLiteral = Result.Nodes.getNodeAs<Expr>("str");
+  if (InitializerList && ConcatenatedLiteral) {
+    // Skip small arrays as they often generate false-positive.
----------------
An early return would be better here.

================
Comment at: clang-tidy/misc/SuspiciousMissingCommaCheck.cpp:45
@@ +44,3 @@
+    unsigned int Size = InitializerList->getNumInits();
+    if (Size < 5)
+      return;
----------------
Should this threshold be an option (or at least a named constant)?

================
Comment at: clang-tidy/misc/SuspiciousMissingCommaCheck.cpp:52
@@ +51,3 @@
+      const Expr* Child = InitializerList->getInit(i)->IgnoreImpCasts();
+      if (const StringLiteral* Literal = dyn_cast<StringLiteral>(Child)) {
+        if (Literal->getNumConcatenated() > 1)
----------------
`const auto *Literal = ...`

================
Comment at: clang-tidy/misc/SuspiciousMissingCommaCheck.cpp:60
@@ +59,3 @@
+    // The current threshold is set to less than 1/5 of the string literals.
+    if ((5 * Count)/Size > 1)
+      return;
----------------
Should this threshold be an option (or at least a named constant)?

================
Comment at: clang-tidy/misc/SuspiciousMissingCommaCheck.cpp:63
@@ +62,3 @@
+
+    diag(ConcatenatedLiteral->getLocStart(), "Suspicious string literal. Probably missing a comma.");
+  }
----------------
No capitalization and trailing periods, please.

Please also clang-format this file.


http://reviews.llvm.org/D18457





More information about the cfe-commits mailing list