Skip to content

Commit

Permalink
[NFC][CodingStandard] Add additional example for if-else brace rule (l…
Browse files Browse the repository at this point in the history
…lvm#111733)

Add example to document that single statement `else` needs a brace if
the associated `if` needs a brace.
  • Loading branch information
jurahul authored and DanielCChen committed Oct 16, 2024
1 parent 2d6fb24 commit dddce94
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions llvm/docs/CodingStandards.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1713,6 +1713,14 @@ would help to avoid running into a "dangling else" situation.
handleOtherDecl(D);
}

// Use braces for the `else` block to keep it uniform with the `if` block.
if (isa<FunctionDecl>(D)) {
verifyFunctionDecl(D);
handleFunctionDecl(D);
} else {
handleOtherDecl(D);
}

// This should also omit braces. The `for` loop contains only a single
// statement, so it shouldn't have braces. The `if` also only contains a
// single simple statement (the `for` loop), so it also should omit braces.
Expand Down

0 comments on commit dddce94

Please sign in to comment.