[PATCH] D19547: [clang-tidy] Add FixIt for swapping arguments in string-constructor-checker.

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 27 04:29:06 PDT 2016


alexfh requested changes to this revision.
This revision now requires changes to proceed.

================
Comment at: clang-tidy/misc/StringConstructorCheck.cpp:110
@@ -106,2 +109,3 @@
   if (Result.Nodes.getNodeAs<Expr>("swapped-parameter")) {
-    diag(Loc, "constructor parameters are probably swapped");
+    assert(E->getNumArgs() == 2 && "Invalid number of arguments");
+    auto D = diag(Loc, "constructor parameters are probably swapped");
----------------
Assertions should verify logical bugs in the code, not some properties of the user input. The matcher doesn't seem to ensure that the argument count is always 2, so it's possible to create code that will trigger this assertion. Either add `argumentCountIs(2)` to the matcher or remove the assertion.


http://reviews.llvm.org/D19547





More information about the cfe-commits mailing list