This code doesn't really make sense (what I really wanted to do was to
compare the underlying lib pointers), but I made this mistake on more
than one occasion:
if (someOptionalBorrowedObject == someSharedObject)
What happens is: since `operator bool` for both types is implicit, they
get implicitly converted to bool. As a result, the condition checks if
both objects contain an object or don't contain an object. I consider
this a pitfall, as it compiles but it is likely never what we'll want to
do.
Make `operator bool` for both types explicit to avoid that. This is
what is done in the STL for `shared_ptr` [1] and `optional` [2].
Note that even if `operator bool` is explicit, it remains implicitly
convertible to bool in certain contexts [3], such as an if condition.
[1] https://en.cppreference.com/w/cpp/memory/shared_ptr/operator_bool
[2] https://en.cppreference.com/w/cpp/utility/optional/operator_bool
[3] https://stackoverflow.com/questions/
39995573/when-can-i-use-explicit-operator-bool-without-a-cast
Change-Id: I2b2377323ca620162442cb7f0305763c034d13d8
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12043
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>