编译器警告(等级 1)C4806

“operation”:不安全的操作:提升到类型 “type” 的类型 “type” 没有值与给定的常量相等

此消息警告针对代码如 b == 3,其中 b 具有类型 bool。 提升规则使 bool 被提升为 int。 这是合法的,但它从不能为 true。 以下示例生成 C4806:

// C4806.cpp
// compile with: /W1
int main()
{
   bool b = true;
   // try..
   // int b = true;

   if (b == 3)   // C4806
   {
      b = false;
   }
}