Commit 9dab2e3
authored
[clang][Sema] Warn on return of pointer/reference to compound literal (#83741)
Emit a warning if pointer/reference to compound literal is returned from
a function.
In C, compound literals in block scope are lvalues that have automatic
storage duration. In C++, compound literals in block scope are
temporaries.
In either case, returning a pointer/reference to a compound literal can
cause a use-after-free bug.
Fixes #86781 parent 0fbe45b commit 9dab2e3
File tree
3 files changed
+15
-3
lines changed- clang
- include/clang/Basic
- lib/Sema
- test/Analysis
3 files changed
+15
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9901 | 9901 | | |
9902 | 9902 | | |
9903 | 9903 | | |
9904 | | - | |
| 9904 | + | |
9905 | 9905 | | |
9906 | 9906 | | |
9907 | 9907 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7734 | 7734 | | |
7735 | 7735 | | |
7736 | 7736 | | |
| 7737 | + | |
| 7738 | + | |
| 7739 | + | |
| 7740 | + | |
| 7741 | + | |
| 7742 | + | |
| 7743 | + | |
| 7744 | + | |
7737 | 7745 | | |
7738 | 7746 | | |
7739 | 7747 | | |
| |||
8289 | 8297 | | |
8290 | 8298 | | |
8291 | 8299 | | |
| 8300 | + | |
| 8301 | + | |
| 8302 | + | |
| 8303 | + | |
8292 | 8304 | | |
8293 | 8305 | | |
8294 | 8306 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| |||
0 commit comments