[PATCH] D33103: [clang-tidy] TwineLocalCheck: add param # checking
Yan Wang via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu May 11 17:36:12 PDT 2017
yawanng updated this revision to Diff 98705.
yawanng added a comment.
Add more tests.
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,35 @@
// 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");
+
+ const Twine t3 = Twine(42);
+// 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 t3 = (Twine(42)).str();
+
+ const Twine t4 = Twine(42) + "b";
+// 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 t4 = (Twine(42) + "b").str();
+
+ const Twine t5 = Twine() + "b";
+// 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 t5 = (Twine() + "b").str();
+
+ const Twine t6 = true ? Twine() : Twine(42);
+// 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 t6 = (true ? Twine() : Twine(42)).str();
+
+ const Twine t7 = false ? Twine() : Twine("b");
+// 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 t7 = (false ? Twine() : Twine("b")).str();
}
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.98705.patch
Type: text/x-patch
Size: 2771 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170512/d9186204/attachment.bin>
More information about the cfe-commits
mailing list