C6315

warning C6315: Incorrect order of operations: bitwise-and has higher precedence than bitwise-or. Add parentheses to clarify intent

This warning indicates that an expression in a test context contains both bitwise-and (&) and bitwise-or (|) operations, but causes a constant because the bitwise-or operation happens last. Parentheses should be added to clarify intent.

Example

The following code generates this warning:

void f( int i )
{
  if ( i & 2 | 4 ) // warning
  {
    // code
  }
}

To correct this warning, add parenthesis as shown in the following code:

void f( int i )
{
  if ( i & ( 2 | 4 ) )
  {
    // code
  }
}