if statement

Conditionally executes another statement.

# Notes

If statement-true or statement-false is not a compound statement, it is treated as if it were:

is the same as

The scope of the name introduced by condition, if it is a declaration, is the combined scope of both statements’ bodies:

If statement-true is entered by goto or longjmp, condition is not evaluated and statement-false is not executed.

Built-in conversions are not allowed in the condition of a constexpr if statement, except for non-narrowing integral conversions to bool.

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
CWG 631C++98the control flow was unspecified if thefirst substatement is reached via a labelthe condition is not evaluated and the secondsubstatement is not executed (same as in C)

# See also