C6315
Visual Studio 2015
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at 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.
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
}
}
Show: