Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V523. The 'then' statement is...
menu mobile close menu
Additional information
toggle menu Contents

V523. The 'then' statement is equivalent to the 'else' statement.

Nov 23 2016

The analyzer has detected that the true and false statements of the if statement completely coincide. This often indicates a logical error.

The example:

if (X)
  Foo_A();
else
  Foo_A();

Whether the X condition is false or true, the Foo_A() function will be called anyway.

The fixed code:

if (X)
  Foo_A();
else
  Foo_B();

The real-world example of this error:

if (!_isVertical)
  Flags |= DT_BOTTOM;
else
  Flags |= DT_BOTTOM;

Presence of two empty statements is considered correct and safe. Such constructions can often be found when using macros.

The example of safe code:

if (exp) {
} else {
}

The analyzer also identifies it as suspicious if the if statement does not contain the else block, and the following code is identical to the conditional statement block, while this code block ends with a return, break, etc.

The suspicious code snippet:

if (X)
{
  doSomething();
  Foo_A();
  return;
}
doSomething();
Foo_A();
return;

Perhaps, the copied code fragment either have not been modified, or redundant code have been added.

This diagnostic is classified as:

You can look at examples of errors detected by the V523 diagnostic.