Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7bf9200

Browse files
committed
CPP: Fix (it looks like we already had a similar test, both are fixed.
1 parent 73b186a commit 7bf9200

4 files changed

Lines changed: 3 additions & 9 deletions

File tree

cpp/ql/src/Likely Bugs/Likely Typos/ExprHasNoEffect.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ where // EQExprs are covered by CompareWhereAssignMeant.ql
9999
not peivc.(FunctionCall).getTarget().hasName("operator==") and
100100
not accessInInitOfForStmt(peivc) and
101101
not peivc.isCompilerGenerated() and
102-
not exists(Macro m | peivc = m.getAnInvocation().getAnExpandedElement()) and
102+
not peivc.isFromTemplateInstantiation(_) and
103103
parent = peivc.getParent() and
104104
not parent.isInMacroExpansion() and
105105
not parent instanceof PureExprInVoidContext and

cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/ExprHasNoEffect.expected

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
| preproc.c:89:2:89:4 | call to fn4 | This expression has no effect (because $@ has no external side effects). | preproc.c:33:5:33:7 | fn4 | fn4 |
22
| preproc.c:94:2:94:4 | call to fn9 | This expression has no effect (because $@ has no external side effects). | preproc.c:78:5:78:7 | fn9 | fn9 |
3-
| template.cpp:4:3:4:3 | call to operator++ | This expression has no effect (because $@ has no external side effects). | template.cpp:9:10:9:19 | operator++ | operator++ |
43
| template.cpp:19:3:19:3 | call to operator++ | This expression has no effect (because $@ has no external side effects). | template.cpp:9:10:9:19 | operator++ | operator++ |
54
| test.c:7:5:7:5 | 0 | This expression has no effect. | test.c:7:5:7:5 | 0 | |
65
| test.c:9:8:9:8 | 1 | This expression has no effect. | test.c:9:8:9:8 | 1 | |
@@ -21,11 +20,6 @@
2120
| test.c:26:15:26:16 | 32 | This expression has no effect. | test.c:26:15:26:16 | 32 | |
2221
| test.c:27:9:27:10 | 33 | This expression has no effect. | test.c:27:9:27:10 | 33 | |
2322
| test.cpp:24:3:24:3 | call to operator++ | This expression has no effect (because $@ has no external side effects). | test.cpp:9:14:9:23 | operator++ | operator++ |
24-
| test.cpp:24:3:24:3 | call to operator++ | This expression has no effect (because $@ has no external side effects). | test.cpp:9:14:9:23 | operator++ | operator++ |
25-
| test.cpp:24:3:24:3 | call to operator++ | This expression has no effect (because $@ has no external side effects). | test.cpp:9:14:9:23 | operator++ | operator++ |
26-
| test.cpp:25:3:25:3 | call to operator++ | This expression has no effect (because $@ has no external side effects). | test.cpp:9:14:9:23 | operator++ | operator++ |
27-
| test.cpp:25:3:25:3 | call to operator++ | This expression has no effect (because $@ has no external side effects). | test.cpp:9:14:9:23 | operator++ | operator++ |
2823
| test.cpp:25:3:25:3 | call to operator++ | This expression has no effect (because $@ has no external side effects). | test.cpp:9:14:9:23 | operator++ | operator++ |
29-
| test.cpp:26:3:26:3 | call to operator++ | This expression has no effect (because $@ has no external side effects). | test.cpp:9:14:9:23 | operator++ | operator++ |
3024
| test.cpp:62:5:62:5 | call to operator= | This expression has no effect (because $@ has no external side effects). | test.cpp:47:14:47:22 | operator= | operator= |
3125
| test.cpp:65:5:65:5 | call to operator= | This expression has no effect (because $@ has no external side effects). | test.cpp:55:7:55:7 | operator= | operator= |

cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/template.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
template<class T>
33
void Increment(T &t) {
4-
t++; // GOOD (sometimes has an effect) [FALSE POSITIVE]
4+
t++; // GOOD (sometimes has an effect)
55
}
66

77
class Nothing {

cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class MyTemplateClass
2323

2424
++arg1; // pure, does nothing
2525
++arg2; // pure, does nothing
26-
++arg3; // not pure in all cases (when _It is int this has a side-effect) [FALSE POSITIVE]
26+
++arg3; // not pure in all cases (when _It is int this has a side-effect)
2727

2828
return arg2;
2929
}

0 commit comments

Comments
 (0)