File tree Expand file tree Collapse file tree 2 files changed +9
-3
lines changed
src/codingstandards/cpp/rules/danglingcapturewhenreturninglambdaobject
test/rules/danglingcapturewhenreturninglambdaobject Expand file tree Collapse file tree 2 files changed +9
-3
lines changed Original file line number Diff line number Diff line change 5
5
*/
6
6
7
7
import cpp
8
- import semmle.code.cpp.dataflow.DataFlow
8
+ import semmle.code.cpp.dataflow.new. DataFlow
9
9
import codingstandards.cpp.Customizations
10
10
import codingstandards.cpp.Exclusions
11
11
@@ -48,7 +48,14 @@ query predicate problems(
48
48
not isExcluded ( returnStmt , getQuery ( ) ) and
49
49
lambda .getACapture ( ) = danglingCapture and
50
50
(
51
- DataFlow:: localExprFlow ( lambda , returnStmt .getExpr ( ) )
51
+ returnStmt .getExpr ( ) = lambda
52
+ or
53
+ exists ( DataFlow:: Node lambdaNode , DataFlow:: Node returnNode |
54
+ lambdaNode .asExpr ( ) = lambda and
55
+ returnNode .asIndirectExpr ( ) = returnStmt .getExpr ( )
56
+ |
57
+ DataFlow:: localFlow ( lambdaNode , returnNode )
58
+ )
52
59
or
53
60
// implement a rough heuristic to catch the results of constructors (such as std::function's)
54
61
// which take an argument that has a dangling capture and flow to a return statement
Original file line number Diff line number Diff line change 1
1
| test.cpp:6:3:6:12 | return ... | Returning lambda $@ with potentially dangling capture $@. | test.cpp:5:12:5:27 | [...](...){...} | object | test.cpp:5:21:5:21 | l1 | l1 |
2
2
| test.cpp:17:5:17:36 | return ... | Returning lambda $@ with potentially dangling capture $@. | test.cpp:17:5:17:36 | [...](...){...} | object | test.cpp:17:27:17:27 | (captured this) | this |
3
3
| test.cpp:27:5:27:17 | return ... | Returning lambda $@ with potentially dangling capture $@. | test.cpp:26:17:26:42 | [...](...){...} | object | test.cpp:26:33:26:33 | val | val |
4
- | test.cpp:27:5:27:17 | return ... | Returning lambda $@ with potentially dangling capture $@. | test.cpp:26:18:26:42 | [...](...){...} | object | test.cpp:26:33:26:33 | val | val |
5
4
| test.cpp:33:3:33:33 | return ... | Returning lambda $@ with potentially dangling capture $@. | test.cpp:33:3:33:33 | [...](...){...} | object | test.cpp:33:25:33:25 | i | i |
6
5
| test.cpp:37:3:37:33 | return ... | Returning lambda $@ with potentially dangling capture $@. | test.cpp:37:3:37:33 | [...](...){...} | object | test.cpp:37:25:37:25 | i | i |
7
6
| test.cpp:46:3:46:45 | return ... | Returning lambda $@ with potentially dangling capture $@. | test.cpp:46:11:46:43 | [...](...){...} | object | test.cpp:46:13:46:16 | data | data |
You can’t perform that action at this time.
0 commit comments