编译器警告(等级 1)C4804

“operation”: 在操作中使用类型“bool”不安全

以非预期方式使用 bool 变量或值时,会出现此警告。 例如,如果使用负一元运算符 (-) 或补码运算符 (~) 等运算符,则会生成 C4804。 编译器计算表达式。

示例

下面的示例生成 C4804:

// C4804.cpp
// compile with: /W1

int main()
{
   bool i = true;
   if (-i)   // C4804, remove the '-' to resolve
   {
      i = false;
   }
}