Repository navigation
Commit aa8b848
committed
Secure the assigned value before destroying the contained value of proxy
- Changed the copy, move, converting and pointer assignments to construct the new value before destroying the contained value of `*this`, because the source may be owned by that value, such as in `p = std::move(p->next)`, which was undefined behavior. When `*this` does not contain a value, the new value is constructed directly in `*this` without a temporary.
- Moved the temporary of the copy and pointer assignments into `*this`, unless it cannot be moved, or moving it may throw while copying it cannot. A second copy is therefore made only for a facade that forbids relocation, or to keep the `noexcept` specification of the copy assignments, and the `noexcept` specifications stay unchanged. `std::move_if_noexcept` was not used, because it copies whenever the move may throw even if the copy may throw too, and it treats a `proxy` that forbids relocation as nothrow movable through its copy constructor.
- Constrained the internal move of a `proxy` like its move constructors, so an rvalue falls back to the internal copy when the facade forbids relocation or requires trivial copyability, as overload resolution does for the constructors. The converting copy assignment of a facade with trivial copyability therefore copies the temporary bytewise instead of relocating it.
- Documented that the source of an assignment may be owned by the contained value of `*this`, how the contained value is initialized from the temporary, and the state of `*this` when an exception is thrown.
- Changed `swap` for facades that forbid relocation to copy directly instead of through the copy assignment, so it still makes three copies.
- Updated the expected operations of the move assignment and of the converting copy assignment of a facade that forbids relocation when the target holds a value, and of the copy and pointer assignments to an empty `proxy`, which no longer make a temporary. Added tests that assign from a value owned by the target for each assignment and check that the source is used before the target value is destroyed, with the value of the pointer assignment test stored inline by `make_proxy_inplace` so that the test also fails when the target value is relocated away before the source is used, tests for the copy and converting copy assignments of a facade with a non-throwing copy that forbids relocation, a test for the copy assignment of a facade with a non-throwing copy whose relocation may throw, a test for the converting copy assignment of a facade with trivial copyability whose relocation may throw, and a static assertion for the `noexcept` specification of the pointer assignment.1 parent 55f13e2 commit aa8b848
3 files changed
Lines changed: 336 additions & 53 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
207 | 213 | | |
208 | 214 | | |
209 | 215 | | |
| |||
1255 | 1261 | | |
1256 | 1262 | | |
1257 | 1263 | | |
1258 | | - | |
1259 | | - | |
1260 | | - | |
1261 | | - | |
1262 | | - | |
1263 | | - | |
1264 | | - | |
| 1264 | + | |
| 1265 | + | |
1265 | 1266 | | |
| 1267 | + | |
| 1268 | + | |
1266 | 1269 | | |
1267 | 1270 | | |
1268 | 1271 | | |
| |||
1277 | 1280 | | |
1278 | 1281 | | |
1279 | 1282 | | |
1280 | | - | |
1281 | | - | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
1282 | 1290 | | |
1283 | 1291 | | |
1284 | 1292 | | |
| |||
1292 | 1300 | | |
1293 | 1301 | | |
1294 | 1302 | | |
1295 | | - | |
1296 | | - | |
1297 | | - | |
1298 | | - | |
1299 | | - | |
1300 | | - | |
| 1303 | + | |
| 1304 | + | |
1301 | 1305 | | |
| 1306 | + | |
| 1307 | + | |
1302 | 1308 | | |
1303 | 1309 | | |
1304 | 1310 | | |
| |||
1314 | 1320 | | |
1315 | 1321 | | |
1316 | 1322 | | |
1317 | | - | |
1318 | | - | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
1319 | 1330 | | |
1320 | 1331 | | |
1321 | 1332 | | |
| |||
1327 | 1338 | | |
1328 | 1339 | | |
1329 | 1340 | | |
1330 | | - | |
1331 | | - | |
1332 | | - | |
1333 | | - | |
1334 | | - | |
1335 | | - | |
1336 | | - | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
1337 | 1344 | | |
1338 | | - | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
1339 | 1348 | | |
1340 | 1349 | | |
1341 | 1350 | | |
| |||
1410 | 1419 | | |
1411 | 1420 | | |
1412 | 1421 | | |
1413 | | - | |
1414 | | - | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
1415 | 1426 | | |
1416 | | - | |
| 1427 | + | |
1417 | 1428 | | |
1418 | 1429 | | |
1419 | 1430 | | |
1420 | | - | |
| 1431 | + | |
1421 | 1432 | | |
1422 | 1433 | | |
1423 | 1434 | | |
| |||
1501 | 1512 | | |
1502 | 1513 | | |
1503 | 1514 | | |
1504 | | - | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
1505 | 1519 | | |
1506 | 1520 | | |
1507 | 1521 | | |
| |||
0 commit comments