Warning C6286

('non-zero constant' || 'expression') is always a non-zero constant. 'expression' is never evaluated and may have side effects

Remarks

This warning indicates that a non-zero constant was detected on the left side of a logical-or operation that occurs in a test context. The resulting expression always evaluates to TRUE. In addition, the right side of the expression appears to have side effects, and they'll be lost.

You may want to examine the right side of the expression carefully to ensure that any side effects needed for proper functionality aren't lost.

The (!0 || <expression>) construction is commonly used to force execution of a controlled block.

Code analysis name: NONZEROLOGICALORLOSINGSIDEEFFECTS

Example

The following code generates this warning:

#include <stdlib.h>
#include <stdio.h>
#define INPUT_TYPE 1

int test();

void f()
{
  if (INPUT_TYPE || test())
  {
    puts("INPUT_TYPE == 1, expression not evaluated");
    // code...
  }
  else
  {
    puts("INPUT_TYPE == 0. Call to test() returned 0");
    // code...
  }
}

The following code shows one possible solution by breaking if statement into two separate parts:

#include <stdlib.h>
#include <stdio.h>
#define INPUT_TYPE 1

int test();

void f()
{
  int i;
  if (INPUT_TYPE)
  {
    i = test();
    // code...
  }
  else
  {
    puts("INPUT_TYPE false");
    // code...
  }
}

See also

Logical OR Operator: ||