brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · be64029 Raw
66 lines · cpp
1// RUN: %check_clang_tidy %s llvm-twine-local %t2 3namespace llvm {4class Twine {5public:6  Twine(const char *);7  Twine(int);8  Twine();9  Twine &operator+(const Twine &);10};11}12 13using namespace llvm;14 15void foo(const Twine &x);16void bar(Twine x);17 18static Twine Moo = Twine("bark") + "bah";19// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: twine variables are prone to use-after-free bugs20// CHECK-MESSAGES: note: FIX-IT applied suggested code changes21// CHECK-FIXES: static std::string Moo = (Twine("bark") + "bah").str();22 23int main() {24  const Twine t = Twine("a") + "b" + Twine(42);25// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: twine variables are prone to use-after-free bugs26// CHECK-MESSAGES: note: FIX-IT applied suggested code changes27// CHECK-FIXES: const std::string t = (Twine("a") + "b" + Twine(42)).str();28  foo(Twine("a") + "b");29 30  Twine Prefix = false ? "__INT_FAST" : "__UINT_FAST";31// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: twine variables are prone to use-after-free bugs32// CHECK-MESSAGES: note: FIX-IT applied suggested code changes33// CHECK-FIXES: const char * Prefix = false ? "__INT_FAST" : "__UINT_FAST";34 35  const Twine t2 = Twine();36// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: twine variables are prone to use-after-free bugs37// CHECK-MESSAGES: note: FIX-IT applied suggested code changes38// CHECK-FIXES: const std::string t2 = (Twine()).str();39  foo(Twine() + "b");40 41  const Twine t3 = Twine(42);42// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: twine variables are prone to use-after-free bugs43// CHECK-MESSAGES: note: FIX-IT applied suggested code changes44// CHECK-FIXES: const std::string t3 = (Twine(42)).str();45 46  const Twine t4 = Twine(42) + "b";47// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: twine variables are prone to use-after-free bugs48// CHECK-MESSAGES: note: FIX-IT applied suggested code changes49// CHECK-FIXES: const std::string t4 = (Twine(42) + "b").str();50 51  const Twine t5 = Twine() + "b";52// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: twine variables are prone to use-after-free bugs53// CHECK-MESSAGES: note: FIX-IT applied suggested code changes54// CHECK-FIXES: const std::string t5 = (Twine() + "b").str();55 56  const Twine t6 = true ? Twine() : Twine(42);57// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: twine variables are prone to use-after-free bugs58// CHECK-MESSAGES: note: FIX-IT applied suggested code changes59// CHECK-FIXES: const std::string t6 = (true ? Twine() : Twine(42)).str();60 61  const Twine t7 = false ? Twine() : Twine("b");62// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: twine variables are prone to use-after-free bugs63// CHECK-MESSAGES: note: FIX-IT applied suggested code changes64// CHECK-FIXES: const std::string t7 = (false ? Twine() : Twine("b")).str();65}66