File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -14,3 +14,21 @@ should be generally avoided.
1414 // becomes
1515
1616 static std::string Moo = (Twine("bark") + "bah").str();
17+
18+ The ``Twine `` does not own the memory of its contents, so it is not
19+ recommended 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 dangling
29+ }
30+
31+ After applying this fix-it hints, the code will use ``std::string `` instead of
32+ ``Twine `` for local variables. However, ``Twine `` has lots of methods that
33+ are incompatible with ``std::string ``, so the user may need to adjust the code
34+ manually after applying the fix-it hints.
You can’t perform that action at this time.
0 commit comments