This revision was automatically updated to reflect the committed changes.
Closed by commit rL346555: [clang-tidy] fix PR39583 - ignoring ParenCast for 
string-literals in pro-bounds… (authored by JonasToth, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D54281

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


Index: 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
===================================================================
--- 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
+++ 
clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
@@ -58,10 +58,11 @@
   // 2) inside a range-for over an array
   // 3) if it converts a string literal to a pointer
   Finder->addMatcher(
-      implicitCastExpr(unless(hasParent(arraySubscriptExpr())),
-                       unless(hasParentIgnoringImpCasts(explicitCastExpr())),
-                       unless(isInsideOfRangeBeginEndStmt()),
-                       unless(hasSourceExpression(stringLiteral())))
+      implicitCastExpr(
+          unless(hasParent(arraySubscriptExpr())),
+          unless(hasParentIgnoringImpCasts(explicitCastExpr())),
+          unless(isInsideOfRangeBeginEndStmt()),
+          unless(hasSourceExpression(ignoringParens(stringLiteral()))))
           .bind("cast"),
       this);
 }
Index: 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp
===================================================================
--- 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp
+++ 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp
@@ -30,6 +30,7 @@
   arrayviewfun(av); // OK
 
   int i = a[0];      // OK
+  int j = a[(1 + 2)];// OK
   pointerfun(&a[0]); // OK
 
   for (auto &e : a) // OK, iteration internally decays array to pointer
@@ -39,6 +40,9 @@
 const char *g() {
   return "clang"; // OK, decay string literal to pointer
 }
+const char *g2() {
+    return ("clang"); // OK, ParenExpr hides the literal-pointer decay
+}
 
 void f2(void *const *);
 void bug25362() {


Index: clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
===================================================================
--- clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProBoundsArrayToPointerDecayCheck.cpp
@@ -58,10 +58,11 @@
   // 2) inside a range-for over an array
   // 3) if it converts a string literal to a pointer
   Finder->addMatcher(
-      implicitCastExpr(unless(hasParent(arraySubscriptExpr())),
-                       unless(hasParentIgnoringImpCasts(explicitCastExpr())),
-                       unless(isInsideOfRangeBeginEndStmt()),
-                       unless(hasSourceExpression(stringLiteral())))
+      implicitCastExpr(
+          unless(hasParent(arraySubscriptExpr())),
+          unless(hasParentIgnoringImpCasts(explicitCastExpr())),
+          unless(isInsideOfRangeBeginEndStmt()),
+          unless(hasSourceExpression(ignoringParens(stringLiteral()))))
           .bind("cast"),
       this);
 }
Index: clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp
===================================================================
--- clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-pro-bounds-array-to-pointer-decay.cpp
@@ -30,6 +30,7 @@
   arrayviewfun(av); // OK
 
   int i = a[0];      // OK
+  int j = a[(1 + 2)];// OK
   pointerfun(&a[0]); // OK
 
   for (auto &e : a) // OK, iteration internally decays array to pointer
@@ -39,6 +40,9 @@
 const char *g() {
   return "clang"; // OK, decay string literal to pointer
 }
+const char *g2() {
+    return ("clang"); // OK, ParenExpr hides the literal-pointer decay
+}
 
 void f2(void *const *);
 void bug25362() {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to