[PATCH] D22196: Fix Bug "28480 - cppcoreguidelines-pro-bounds-array-to-pointer-decay handling __PRETTY_FUNCTION__"

Eric Lemanissier via cfe-commits cfe-commits at lists.llvm.org
Sun Jul 10 06:44:47 PDT 2016


ericLemanissier created this revision.
ericLemanissier added reviewers: alexfh, sbenza, bkramer, aaron.ballman.
ericLemanissier added subscribers: ericLemanissier, cfe-commits.
Herald added a subscriber: nemanjai.

Ignore array to pointer decay for predefined macros. It is ok because there is no safer way to pass these macros to functions

http://reviews.llvm.org/D22196

Files:
  clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
  test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp

Index: test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp
===================================================================
--- test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp
+++ test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp
@@ -45,3 +45,10 @@
   void *a[2];
   f2(static_cast<void *const*>(a)); // OK, explicit cast
 }
+
+void cstringfun(const char *s);
+void bug28480() {
+    cstringfun(__PRETTY_FUNCTION__);    //OK, predefined macro
+    cstringfun(__func__);               //OK, predefined macro
+    cstringfun(__FUNCTION__);           //OK, predefined macro
+}
Index: clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
===================================================================
--- clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
+++ clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
@@ -59,7 +59,8 @@
       implicitCastExpr(unless(hasParent(arraySubscriptExpr())),
                        unless(hasParentIgnoringImpCasts(explicitCastExpr())),
                        unless(isInsideOfRangeBeginEndStmt()),
-                       unless(hasSourceExpression(stringLiteral())))
+                       unless(hasSourceExpression(stringLiteral())),
+                       unless(hasDescendant(predefinedExpr())))
           .bind("cast"),
       this);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22196.63424.patch
Type: text/x-patch
Size: 1400 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160710/1096d120/attachment.bin>


More information about the cfe-commits mailing list