| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,11 +9,24 @@ | |||
| 9 | 9 | */ | |
| 10 | 10 | ||
| 11 | 11 | import cpp | |
| 12 | + import semmle.code.cpp.commons.Exclusions | ||
| 12 | 13 | ||
| 13 | - from CommaExpr ce | ||
| 14 | + Expr normalizeExpr(Expr e) { | ||
| 15 | + if exists(e.(Call).getQualifier()) | ||
| 16 | + then result = normalizeExpr(e.(Call).getQualifier()) | ||
| 17 | + else | ||
| 18 | + if e.hasExplicitConversion() | ||
| 19 | + then result = normalizeExpr(e.getFullyConverted()) | ||
| 20 | + else result = e | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + from CommaExpr ce, Expr left, Expr right, int leftStartColumn, int rightStartColumn | ||
| 14 | 24 | where | |
| 15 | 25 | ce.fromSource() and | |
| 16 | - not exists(MacroInvocation me | ce = me.getAnAffectedElement()) and | ||
| 17 | - ce.getLeftOperand().getLocation().getStartColumn() > | ||
| 18 | - ce.getRightOperand().getLocation().getStartColumn() | ||
| 19 | - select ce, "Comma before misleading indentation." | ||
| 26 | + not isFromMacroDefinition(ce) and | ||
| 27 | + left = normalizeExpr(ce.getLeftOperand()) and | ||
| 28 | + right = normalizeExpr(ce.getRightOperand()) and | ||
| 29 | + leftStartColumn = left.getLocation().getStartColumn() and | ||
| 30 | + rightStartColumn = right.getLocation().getStartColumn() and | ||
| 31 | + leftStartColumn > rightStartColumn | ||
| 32 | + select right, "The indentation level after the comma can be misleading (for some tab sizes)." | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,7 +36,7 @@ int test(int i, int j, int (*foo)(int), int (*bar)(int, int)) | |||
| 36 | 36 | ||
| 37 | 37 | x.foo(i++), j++; // GOOD | |
| 38 | 38 | (x.foo(i++), j++); // GOOD | |
| 39 | - (x.foo(i++), // GOOD [FALSE POSITIVE] | ||
| 39 | + (x.foo(i++), // GOOD | ||
| 40 | 40 | j++); | |
| 41 | 41 | (x.foo(i++), | |
| 42 | 42 | j++); // BAD (?) | |
@@ -50,7 +50,7 @@ int test(int i, int j, int (*foo)(int), int (*bar)(int, int)) | |||
| 50 | 50 | ||
| 51 | 51 | (void)(i++), j++; // GOOD | |
| 52 | 52 | ((void)(i++), j++); // GOOD | |
| 53 | - ((void)(i++), // GOOD [FALSE POSITIVE] | ||
| 53 | + ((void)(i++), // GOOD | ||
| 54 | 54 | j++); | |
| 55 | 55 | ((void)(i++), | |
| 56 | 56 | j++); // BAD (?) | |
@@ -73,9 +73,9 @@ int test(int i, int j, int (*foo)(int), int (*bar)(int, int)) | |||
| 73 | 73 | BAR(i++, | |
| 74 | 74 | j++); // GOOD: common pattern and unlikely to be misread. | |
| 75 | 75 | ||
| 76 | - using T = decltype(x.foo(i++), // GOOD [FALSE POSITIVE] | ||
| 76 | + using T = decltype(x.foo(i++), // GOOD | ||
| 77 | 77 | j++); | |
| 78 | - (void)sizeof(x.foo(i++), // GOOD [FALSE POSITIVE] | ||
| 78 | + (void)sizeof(x.foo(i++), // GOOD | ||
| 79 | 79 | j++); | |
| 80 | 80 | ||
| 81 | 81 | // Comma in loops | |
| Back | FazBrowse Home | New Git URL |
0 commit comments