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

19.11.2010

The analyzer found a case when the true and false statements of the 'if' operator coincide completely. This often signals a logical error.

Here is an example:

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

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

This is the correct version of the code:

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

Here is an example of such an error taken from a real application:

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

Presence of two empty statements is considered correct and safe. You might often see such constructs when using macros. This is a sample of safe code:

if (exp) {
} else {
}
You can look at examples of errors from real projects which were detected by this diagnostic message.