Commit dda2349
Make
Summary:
`visit_union` is taking the callable by value, forcing a copy.
This is a problem because
1. it's inconsistent with `std::visit`, which instead uses universal references. This results in surprises when using it
2. when the callable returns a coroutine, this guarantees that the coroutine state is destoryed before the coroutine finish execution
```
int a = 0
co_await thrift::visit_union(my_union, [&](auto, auto) -> Task<void> { a += 1; co_return; });
```
This results in a dangling reference in the old implementation, and it's correct in the new one.
This is consistent with the coro wiki: https://www.internalfb.com/wiki/Coro/#lambdas
Note: To be consistent the same should probably be done to also `visit_by_thrift_field_metadata` and the other visit functions
Triggering problem: https://fb.workplace.com/groups/192968587972839/posts/1656198051649878/?comment_id=1657068398229510&reply_comment_id=1657106148225735
Reviewed By: Mizuchi
Differential Revision: D68151611
fbshipit-source-id: a05c53043642b4274dbab63316e6dcb7d21de9f4visit_union take the callable by universal reference1 parent 8a71f98 commit dda2349
File tree
2 files changed
+6
-4
lines changed- third-party/thrift/src/thrift
- lib/cpp2/visitation
- test/reflection
2 files changed
+6
-4
lines changedLines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
151 | | - | |
| 151 | + | |
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
| 155 | + | |
| 156 | + | |
155 | 157 | | |
156 | 158 | | |
157 | 159 | | |
| |||
0 commit comments