Commit d817854
committed
gcc: Fix
`detach_abi(com_array<T>&)` uses two `memset` calls to zero two objects,
one is an `std::pair` (from [microsoft#1165]), the other is a `winrt::com_array`
(to clear its data pointer to prevent its destructor from freeing the
array). GCC rightfully warns about this because these types are not
trivially copyable, so calling memset on it is UB.
This change fixes the UB and the GCC warning by reverting the first
`memset` back to using the `std::pair` constructor as before [microsoft#1165],
and changing the second `memset` to setting the member fields directly.
Since this requires access to protected members, the function body is
moved into a private member function, then the `winrt::detach_abi` free
function is made `friend` of `com_array` to allow it to call the member
function.
This fix is not applied when `_MSC_VER` is defined in order to preserve
the current behaviour on MSVC, in case [microsoft#1165] is still relevant.
[microsoft#1165]: microsoft#1165-Wclass-memaccess warning1 parent 9fe0157 commit d817854
1 file changed
Lines changed: 22 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
345 | 345 | | |
346 | 346 | | |
347 | 347 | | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
348 | 368 | | |
349 | 369 | | |
350 | 370 | | |
| |||
418 | 438 | | |
419 | 439 | | |
420 | 440 | | |
421 | | - | |
| 441 | + | |
422 | 442 | | |
423 | | - | |
424 | | - | |
425 | | - | |
426 | | - | |
427 | | - | |
428 | | - | |
| 443 | + | |
429 | 444 | | |
430 | 445 | | |
431 | 446 | | |
| |||
0 commit comments