Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Visual Studio 2019 and later:
Implicit conversion from 'type' to bool. Possible information loss
C4800 is a level 3 warning in Visual Studio 2015 and earlier:
'type' : forcing value to bool 'true' or 'false' (performance warning)
Remarks
This warning is generated when a value is implicitly converted into type bool. Typically, this message is caused by assigning int variables to bool variables where the int variable contains only values true and false, and could be redeclared as type bool. If you can't rewrite the expression to use type bool, then you can add "!=0" to the expression, which gives the expression type bool. Casting the expression to type bool doesn't disable the warning, which is by design.
This warning is not emitted in Visual Studio 2017.
This warning is off by default starting in Visual Studio 2019. Use /wn4800 to enable C4800 as a level n warning, or /Wall to enable all warnings that are off by default. For more information, see Compiler Warnings That Are Off By Default.
Example
The following example generates C4800 and shows how to fix it:
// C4800.cpp
// compile with: /W4 /w44800
int main() {
int i = 0;
// To fix, instead try:
// bool i = 0;
bool j = i; // C4800
j++;
}