From c763a4087f1d8fa4dbdfb9c8f30d545cdb66a0aa Mon Sep 17 00:00:00 2001 From: Julian Büning Date: Sat, 10 Oct 2020 15:13:06 +0200 Subject: Ref: implement operator bool() --- include/klee/ADT/Ref.h | 13 +++++++------ include/klee/Expr/Expr.h | 4 +--- 2 files changed, 8 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/include/klee/ADT/Ref.h b/include/klee/ADT/Ref.h index 92fd1740..7267f894 100644 --- a/include/klee/ADT/Ref.h +++ b/include/klee/ADT/Ref.h @@ -217,6 +217,7 @@ public: } bool isNull() const { return ptr == nullptr; } + explicit operator bool() const noexcept { return !isNull(); } // assumes non-null arguments int compare(const ref &rhs) const { @@ -245,12 +246,12 @@ inline std::stringstream &operator<<(std::stringstream &os, const ref &e) { } // end namespace klee namespace llvm { - // simplify_type implementation for ref<>, which allows dyn_cast from on a - // ref<> to apply to the wrapper type. Conceptually the result of such a - // dyn_cast should probably be a ref of the casted type, but that breaks the - // idiom of initializing a variable to the result of a dyn_cast inside an if - // condition, or we would have to implement operator(bool) for ref<> with - // isNull semantics, which doesn't seem like a good idea. +// simplify_type implementation for ref<>, which allows dyn_cast on a +// ref<> to apply to the wrapper type. Conceptually the result of such a +// dyn_cast should probably be a ref of the casted type, which historically +// was breaking the idiom of initializing a variable to the result of a dyn_cast +// inside an if condition, as ref<> did not have an operator bool() with isNull +// semantics. template struct simplify_type > { using SimpleType = T *; diff --git a/include/klee/Expr/Expr.h b/include/klee/Expr/Expr.h index c5d1e7bb..b509294c 100644 --- a/include/klee/Expr/Expr.h +++ b/include/klee/Expr/Expr.h @@ -553,9 +553,7 @@ public: UpdateList &operator=(const UpdateList &b) = default; /// size of this update list - unsigned getSize() const { - return (head.get() != nullptr ? head->getSize() : 0); - } + unsigned getSize() const { return head ? head->getSize() : 0; } void extend(const ref &index, const ref &value); -- cgit 1.4.1