BullseyeCoverage
Microsoft C++ |
error C2440: '?' : cannot convert from ' type' to 'bool'
|
GNU C++ |
error: could not convert ' type' to 'bool'
|
Clang |
error: value of type ' type' is not contextually convertible to 'bool'
|
A declaration of operator&&
or operator||
is incompatible with operands or a result of type bool
.
Defining these operators with operand type or return type other than bool
conflicts
with condition/decision coverage at a basic level, and is not compatible with BullseyeCoverage.
It is recommended to first try the latest release .
Alternative options are listed below in order of preference.
&&
and ||
to
conventional function names.
operator&
or operator|
rather than operator&&
or operator||
.
operator&&
and operator||
.
For example,
// a = b && c; ← change this a = b.operator&&(c); ← to this
operator&&
or operator||
,
instead define operator bool()
to convert all expressions to
boolean values,
and then use the built-in &&
and ||
operators
on the boolean values.
For example,
class C { public: //bool operator&&(const C&) const; ← remove this //bool operator||(const C&) const; ← remove this operator bool() const; ← add this }; C c1, c2; if (c1 && c2) if (c1 || c2)
operator&&
or operator||
.
See also Best Practice Recommendations.
Updated: 3 Sep 2024
Copyright © Bullseye Testing Technology. All Rights Reserved.