35 lines · plain
1.. title:: clang-tidy - llvm-twine-local2 3llvm-twine-local4================5 6 7Looks for local ``Twine`` variables which are prone to use after frees and8should be generally avoided.9 10.. code-block:: c++11 12 static Twine Moo = Twine("bark") + "bah";13 14 // becomes15 16 static std::string Moo = (Twine("bark") + "bah").str();17 18The ``Twine`` does not own the memory of its contents, so it is not19recommended to use ``Twine`` created from temporary strings or string literals.20 21.. code-block:: c++22 23 static Twine getModuleIdentifier(StringRef moduleName) {24 return moduleName + "_module";25 }26 void foo() {27 Twine result = getModuleIdentifier(std::string{"abc"} + "def");28 // temporary std::string is destroyed here, result is dangling29 }30 31After applying this fix-it hints, the code will use ``std::string`` instead of32``Twine`` for local variables. However, ``Twine`` has lots of methods that33are incompatible with ``std::string``, so the user may need to adjust the code34manually after applying the fix-it hints.35