[PATCH] D33103: [clang-tidy] TwineLocalCheck: add param # checking

Yan Wang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 11 15:04:48 PDT 2017


yawanng updated this revision to Diff 98684.

https://reviews.llvm.org/D33103

Files:
  clang-tidy/llvm/TwineLocalCheck.cpp
  test/clang-tidy/llvm-twine-local.cpp


Index: test/clang-tidy/llvm-twine-local.cpp
===================================================================
--- test/clang-tidy/llvm-twine-local.cpp
+++ test/clang-tidy/llvm-twine-local.cpp
@@ -5,6 +5,7 @@
 public:
   Twine(const char *);
   Twine(int);
+  Twine();
   Twine &operator+(const Twine &);
 };
 }
@@ -29,4 +30,10 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: twine variables are prone to use-after-free bugs
 // CHECK-MESSAGES: note: FIX-IT applied suggested code changes
 // CHECK-FIXES: const char * Prefix = false ? "__INT_FAST" : "__UINT_FAST";
+
+  const Twine t2 = Twine();
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: twine variables are prone to use-after-free bugs
+// CHECK-MESSAGES: note: FIX-IT applied suggested code changes
+// CHECK-FIXES: std::string t2 = (Twine()).str();
+  foo(Twine() + "b");
 }
Index: clang-tidy/llvm/TwineLocalCheck.cpp
===================================================================
--- clang-tidy/llvm/TwineLocalCheck.cpp
+++ clang-tidy/llvm/TwineLocalCheck.cpp
@@ -35,8 +35,11 @@
     // of the initializer.
     const Expr *C = VD->getInit()->IgnoreImplicit();
 
-    while (isa<CXXConstructExpr>(C))
+    while (isa<CXXConstructExpr>(C)) {
+      if (cast<CXXConstructExpr>(C)->getNumArgs() == 0)
+        break;
       C = cast<CXXConstructExpr>(C)->getArg(0)->IgnoreParenImpCasts();
+    }
 
     SourceRange TypeRange =
         VD->getTypeSourceInfo()->getTypeLoc().getSourceRange();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33103.98684.patch
Type: text/x-patch
Size: 1454 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170511/a40d96f3/attachment.bin>


More information about the cfe-commits mailing list