Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions clang-tools-extra/docs/clang-tidy/checks/llvm/twine-local.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'm little confused why we sometimes use Twine and sometimes llvm::Twine. Could we always use one variant (like Twine)


.. 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.
Loading