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);
 }


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);
 }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to