I have searched on google but I have no luck to find the cause of this warning Wint-in-bool-context
The compiler gives me the following warning:
warning: enum constant in boolean context [-Wint-in-bool-context]
: (excess_bits ? (((uint64_t)VAL) << (excess_bits)) >> (excess_bits)
~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
: (uint64_t)VAL));
This is the code line related with this warning:
std::vector<ap_int<32>> B(n*m);
for(int i = 0;i < m;i++){
...
B.data()[i * n + j] = 0x00000001;
...
}
-Wint-in-bool-context
is exactly as it sounds. You're using an integer value and allowing it to behave implicitly like a bool
(e.g. any nonzero value is true
).
In your (limited) snippet, it's likely because excess_bits
is an integral value and not bool
. To silence such a warning, explicitly cast instead, or perform a check that evaluates to a boolean expression -- such as:
: (static_cast<bool>(excess_bits) ? (((uint64_t)VAL) << (excess_bits)) >> (excess_bits)
// ^~~~~~~~~~~~~~~~~~~ ~ Tell compiler we want a bool
Or
: ((excess_bits != 0) ? (((uint64_t)VAL) << (excess_bits)) >> (excess_bits)
The second snippet you provide is less clear because we don't have the error, exact offending line, or the definition of ap_int<32>
. If I had to guess, the assignment of
B.data()[i * n + j] = 0x00000001;
Should probably be assigning true
instead of a numeric value; but this is just a guess, since no context has been given here.
User contributions licensed under CC BY-SA 3.0