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.
Reviewers: jyknight
Reviewed By: jyknight
Subscribers: dexonsmith, kristina, llvm-commits
Differential Revision: https://reviews.llvm.org/D56870
llvm-svn: 351572
assert(isValid() && "Invalid twine!");
}
+ /// Delete the implicit conversion from nullptr as Twine(const char *)
+ /// cannot take nullptr.
+ /*implicit*/ Twine(std::nullptr_t) = delete;
/// Construct from an std::string.
/*implicit*/ Twine(const std::string &Str) : LHSKind(StdStringKind) {
}
Value *foldConstant(Instruction::BinaryOps Opc, Value *L,
- Value *R, const Twine &Name = nullptr) const {
+ Value *R, const Twine &Name) const {
auto *LC = dyn_cast<Constant>(L);
auto *RC = dyn_cast<Constant>(R);
return (LC && RC) ? Insert(Folder.CreateBinOp(Opc, LC, RC), Name) : nullptr;