This is an archive of the discontinued LLVM Phabricator instance.

Disallow StringRef assignment from temporary std::strings.
ClosedPublic

Authored by jordan_rose on Nov 4 2016, 5:18 PM.

Details

Summary

Similar to D25446, this prevents accidentally referring to temporary storage that goes out of scope by the end of the statement:

someStringRef = getStringByValue();
someStringRef = (Twine("-") + otherString).str();

Note that once again the constructor still has this problem:

StringRef someStringRef = getStringByValue();

because once again we occasionally rely on this in calls:

takesStringRef(getStringByValue());
takesStringRef(Twine("-") + otherString);

Still, it's a step, and it caught one real problem in Clang and one in Swift.

Depends on D26317

Diff Detail

Repository
rL LLVM

Event Timeline

jordan_rose updated this revision to Diff 76957.Nov 4 2016, 5:18 PM
jordan_rose retitled this revision from to Disallow StringRef assignment from temporary std::strings..
jordan_rose updated this object.
jordan_rose added a reviewer: dexonsmith.
jordan_rose set the repository for this revision to rL LLVM.
jordan_rose added a subscriber: llvm-commits.
vsk added a subscriber: vsk.Nov 5 2016, 12:55 PM
jordan_rose accepted this revision.Nov 7 2016, 12:46 PM
jordan_rose added a reviewer: jordan_rose.

Approved by Duncan via email.

This revision is now accepted and ready to land.Nov 7 2016, 12:46 PM
jordan_rose closed this revision.Nov 7 2016, 12:50 PM

Committed in r286139, accidentally omitting the tests. Tests added in r286141.