C6315
Note
This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here
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
}
}