[clang-tools-extra] e856483 - [clang-tidy][doc] add more information in twine-local's document (#166266)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 5 03:25:57 PST 2025
Author: Congcong Cai
Date: 2025-11-05T11:25:53Z
New Revision: e8564830c19e6fd5bfa38488c06f332b214ea858
URL: https://github.com/llvm/llvm-project/commit/e8564830c19e6fd5bfa38488c06f332b214ea858
DIFF: https://github.com/llvm/llvm-project/commit/e8564830c19e6fd5bfa38488c06f332b214ea858.diff
LOG: [clang-tidy][doc] add more information in twine-local's document (#166266)
explain more about use-after-free in llvm-twine-local
add note about manually adjusting code after applying fix-it.
fixed: #154810
Added:
Modified:
clang-tools-extra/docs/clang-tidy/checks/llvm/twine-local.rst
Removed:
################################################################################
diff --git a/clang-tools-extra/docs/clang-tidy/checks/llvm/twine-local.rst b/clang-tools-extra/docs/clang-tidy/checks/llvm/twine-local.rst
index ec9ef1c60913c..6c994a48d83de 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/llvm/twine-local.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/llvm/twine-local.rst
@@ -14,3 +14,21 @@ should be generally avoided.
// becomes
static std::string Moo = (Twine("bark") + "bah").str();
+
+The ``Twine`` does not own the memory of its contents, so it is not
+recommended to use ``Twine`` created from temporary strings or string literals.
+
+.. code-block:: c++
+
+ static Twine getModuleIdentifier(StringRef moduleName) {
+ return moduleName + "_module";
+ }
+ void foo() {
+ Twine result = getModuleIdentifier(std::string{"abc"} + "def");
+ // temporary std::string is destroyed here, result is dangling
+ }
+
+After applying this fix-it hints, the code will use ``std::string`` instead of
+``Twine`` for local variables. However, ``Twine`` has lots of methods that
+are incompatible with ``std::string``, so the user may need to adjust the code
+manually after applying the fix-it hints.
More information about the cfe-commits
mailing list