This is an archive of the discontinued LLVM Phabricator instance.

[adt] Twine(nullptr) derefs the nullptr. Add a deleted Twine(std::nullptr_t)
ClosedPublic

Authored by dsanders on Jan 17 2019, 11:35 AM.

Details

Summary

nullptr can implicitly convert to Twine as Twine(nullptr) in which case it
resolves to Twine(const char *). This constructor derefs the pointer and
therefore doesn't work. Add a Twine(std::nullptr_t) = delete to make it a
compile time error.

It turns out that in-tree usage of Twine(nullptr) is confined to a single
private method in IRBuilder where foldConstant(... const Twine &Name = nullptr)
and this method is only ever called with an explicit Name argument as making it
a mandatory argument doesn't cause compile-time or run-time errors.

Diff Detail

Event Timeline

dsanders created this revision.Jan 17 2019, 11:35 AM
jyknight accepted this revision.Jan 17 2019, 12:51 PM
This revision is now accepted and ready to land.Jan 17 2019, 12:51 PM
This revision was automatically updated to reflect the committed changes.