Skip to content

Commit 0e9b77e

Browse files
committed
C++: Initial .qhelp file
1 parent dca13f5 commit 0e9b77e

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Here, the comma should have been a semicolon:
3+
*/
4+
5+
enum privileges entitlements = NONE;
6+
7+
if (is_admin)
8+
entitlements = FULL, // BAD
9+
10+
restrict_privileges(entitlements);
11+
12+
/*
13+
* This is misleading, because the code is unexpectedly equivalent to:
14+
*/
15+
16+
enum privileges entitlements = NONE;
17+
18+
if (is_admin) {
19+
entitlements = FULL;
20+
restrict_privileges(entitlements);
21+
}
22+
23+
/*
24+
* Whereas the following code was probably intended:
25+
*/
26+
27+
enum privileges entitlements = NONE;
28+
29+
if (is_admin)
30+
entitlements = FULL; // GOOD
31+
32+
restrict_privileges(entitlements);

cpp/ql/src/Best Practices/Likely Errors/CommaBeforeMisleadingIndentation.qhelp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@
44
<qhelp>
55

66
<overview>
7-
<p>...</p>
7+
<p>
8+
If the expression to the right of a comma operator starts at an earlier column than the expression to the left, then
9+
this suspicious indentation likely indicates a logic error caused by a typo that may escape visual inspection.
10+
</p>
811
</overview>
912

1013
<recommendation>
11-
<p>...</p>
14+
<p>
15+
Use standard indentation around the comma operator: begin the right-hand-side operand at the same level of
16+
indentation as the left-hand-side operand.
17+
</p>
1218
</recommendation>
1319

1420
<example>

0 commit comments

Comments
 (0)