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