[PATCH] D13640: [clang-tidy] Add new check cppcoreguidelines-pro-bounds-array-to-pointer-decay

Matthias Gehre via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 12 15:57:53 PDT 2015


mgehre added inline comments.

================
Comment at: clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp:29
@@ +28,3 @@
+      implicitCastExpr(unless(hasParent(arraySubscriptExpr())),
+                       unless(hasSourceExpression(declRefExpr(to(varDecl(hasName("__range")))))),
+                       unless(hasSourceExpression(stringLiteral()))
----------------
sbenza wrote:
> __range is an implementation detail and should not be used here.
> Check that this is the range init of a cxxForRangeStmt parent node or something like that.
That was my first attempt, but I couldn't quite figure it out.

I tried
  unless(hasAncestor(cxxForRangeStmt(hasRangeInit(hasDescendant(equalsBoundNode("cast"))))))
but that does not compile.

Any ideas?

================
Comment at: test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp:12
@@ +11,3 @@
+  pointerfun((int*)a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: do not (implicitly) convert an array to a pointer
+  arrayfun(a);
----------------
sbenza wrote:
> this is not implicit. Is the 'implicit' optional?
Currently, the diag is
  diag(MatchedCast->getExprLoc(), "do not (implicitly) convert an array to a pointer");
should I make the parenthesis conditional?


http://reviews.llvm.org/D13640





More information about the cfe-commits mailing list