Skip to content

Commit e54909d

Browse files
[clang-tidy] Update documentation for
'bugprone-inconsistent-ifelse-braces'
1 parent 18e6ae8 commit e54909d

File tree

5 files changed

+48
-13
lines changed

5 files changed

+48
-13
lines changed

clang-tools-extra/clang-tidy/bugprone/InconsistentIfelseBracesCheck.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
//===----------------------------------------------------------------------===//
32
//
43
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -62,17 +61,15 @@ void InconsistentIfelseBracesCheck::checkIfStmt(
6261
// it, then we need to check the inner IfStmt.
6362
checkStmt(Result, If->getThen(), If->getRParenLoc(), If->getElseLoc());
6463
if (shouldHaveBraces(NestedIf))
65-
return checkIfStmt(Result, NestedIf);
66-
}
67-
68-
if (!isa<CompoundStmt>(Then))
64+
checkIfStmt(Result, NestedIf);
65+
} else if (!isa<CompoundStmt>(Then)) {
6966
checkStmt(Result, If->getThen(), If->getRParenLoc(), If->getElseLoc());
67+
}
7068

7169
if (const Stmt *const Else = If->getElse()) {
7270
if (const auto *NestedIf = dyn_cast<const IfStmt>(Else))
73-
return checkIfStmt(Result, NestedIf);
74-
75-
if (!isa<CompoundStmt>(Else))
71+
checkIfStmt(Result, NestedIf);
72+
else if (!isa<CompoundStmt>(Else))
7673
checkStmt(Result, If->getElse(), If->getElseLoc());
7774
}
7875
}
@@ -92,4 +89,5 @@ void InconsistentIfelseBracesCheck::checkStmt(
9289
}
9390
}
9491
}
92+
9593
} // namespace clang::tidy::bugprone

clang-tools-extra/clang-tidy/bugprone/InconsistentIfelseBracesCheck.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
//===----------------------------------------------------------------------===//
32
//
43
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -14,7 +13,8 @@
1413

1514
namespace clang::tidy::bugprone {
1615

17-
/// FIXME: Write a short description.
16+
/// Detects ``if``/``else`` statements where one branch uses braces and the
17+
/// other does not.
1818
///
1919
/// For the user-facing documentation see:
2020
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/inconsistent-ifelse-braces.html

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ New checks
160160
- New :doc:`bugprone-inconsistent-ifelse-braces
161161
<clang-tidy/checks/bugprone/inconsistent-ifelse-braces>` check.
162162

163-
FIXME: Write a short description.
163+
Detects ``if``/``else`` statements where one branch uses braces and the other
164+
does not.
164165

165166
- New :doc:`bugprone-invalid-enum-default-initialization
166167
<clang-tidy/checks/bugprone/invalid-enum-default-initialization>` check.

clang-tools-extra/docs/clang-tidy/checks/bugprone/inconsistent-ifelse-braces.rst

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,40 @@
33
bugprone-inconsistent-ifelse-braces
44
===================================
55

6-
FIXME: Describe what patterns does the check detect and why. Give examples.
6+
Detects ``if``/``else`` statements where one branch uses braces and the other
7+
does not.
8+
9+
Before:
10+
11+
.. code-block:: c++
12+
13+
if (condition) {
14+
statement;
15+
} else
16+
statement;
17+
18+
if (condition)
19+
statement;
20+
21+
if (condition)
22+
statement;
23+
else
24+
statement;
25+
26+
After:
27+
28+
.. code-block:: c++
29+
30+
if (condition) {
31+
statement;
32+
} else {
33+
statement;
34+
}
35+
36+
if (condition)
37+
statement;
38+
39+
if (condition)
40+
statement;
41+
else
42+
statement;

clang-tools-extra/docs/clang-tidy/checks/list.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ Clang-Tidy Checks
101101
:doc:`bugprone-implicit-widening-of-multiplication-result <bugprone/implicit-widening-of-multiplication-result>`, "Yes"
102102
:doc:`bugprone-inaccurate-erase <bugprone/inaccurate-erase>`, "Yes"
103103
:doc:`bugprone-inc-dec-in-conditions <bugprone/inc-dec-in-conditions>`,
104-
:doc:`bugprone-inconsistent-ifelse-braces <bugprone/inconsistent-ifelse-braces>`,
104+
:doc:`bugprone-inconsistent-ifelse-braces <bugprone/inconsistent-ifelse-braces>`, "Yes"
105105
:doc:`bugprone-incorrect-enable-if <bugprone/incorrect-enable-if>`, "Yes"
106106
:doc:`bugprone-incorrect-enable-shared-from-this <bugprone/incorrect-enable-shared-from-this>`, "Yes"
107107
:doc:`bugprone-incorrect-roundings <bugprone/incorrect-roundings>`,

0 commit comments

Comments
 (0)