This allows the use of isl::boolean values as first operand of
__builtin_assume(long, long) without the need for explicit casts. This is
useful as OSX uses __builtin_assume in its implementation of assert() to
indicate to the compiler that the condition that is verified is true with high
probability. Without allowing implicit conversions to bool, the use
of isl::boolean without an explicit cast to bool results in
a compilation failure on OSX. As explicit casts seem too verbose to be used in
each assert call, this change allows implicit conversions from boolean
to bool.
Originally, implicit conversions from boolean to bool were disallowed to start
off with a minimal C++ interface that is as explicit as possible. This
minimal interface was understood to be widened in case practical use
cases motivate an extended interface. Extending the interface to avoid
many explicit casts in common situtations is exactly such a practical
use case.
Also update the tests. Incorrectly, the tests already assumed that
'assert(b_true)' would test implicit conversions. This was not the case
and new test cases have been added that test implicit conversion to both
bool and long.
Suggested-by: Siddharth Bath <
siddhar...@research.iiit.ac.in>
Signed-off-by: Tobias Grosser <
tob...@grosser.es>
---
interface/isl.h.top | 2 +-
interface/isl_test_cpp.cpp | 17 +++++++++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/interface/isl.h.top b/interface/isl.h.top
index 37749c2..56312d2 100644
--- a/interface/isl.h.top
+++ b/interface/isl.h.top
@@ -55,7 +55,7 @@ public:
bool is_false() const { return val == isl_bool_false; }
bool is_true() const { return val == isl_bool_true; }
- explicit operator bool() const {
+ operator bool() const {
ISLPP_ASSERT(!is_error(), "IMPLEMENTATION ERROR: Unhandled error state");
return is_true();
}
diff --git a/interface/isl_test_cpp.cpp b/interface/isl_test_cpp.cpp
index 6059208..e85d770 100644
--- a/interface/isl_test_cpp.cpp
+++ b/interface/isl_test_cpp.cpp
@@ -188,6 +188,7 @@ void test_return_int(isl::ctx ctx)
* respectively
* - Explicit conversion to 'bool'
* - Implicit conversion to 'bool'
+ * - Implicit conversion to 'long'
* - The complement operator
* - Explicit construction from 'true' and 'false'
* - Explicit construction form isl_bool
@@ -219,6 +220,22 @@ void test_return_bool(isl::ctx ctx)
assert(b_true);
+ bool use_in_bool_expr = b_true && true;
+ bool use_in_bool_expr_2 = true && b_true;
+
+ assert(use_in_bool_expr == use_in_bool_expr_2 &&
+ use_in_bool_expr == true);
+
+ bool bool_true = b_true;
+ bool bool_false = b_false;
+
+ assert(bool_true && !bool_false);
+
+ long long_true = b_true;
+ long long_false = b_false;
+
+ assert(long_true && !long_false);
+
assert((!b_false).is_true());
assert((!b_true).is_false());
assert((!b_error).is_error());
--
2.9.3