Bug 290825
| Summary: | [TestWTF] Work around compiler bug in TypeCastsCocoa.mm test | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | David Kilzer (:ddkilzer) <ddkilzer> |
| Component: | Tools / Tests | Assignee: | David Kilzer (:ddkilzer) <ddkilzer> |
| Status: | RESOLVED FIXED | ||
| Severity: | Normal | CC: | webkit-bug-importer |
| Priority: | P2 | Keywords: | InRadar |
| Version: | Other | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
| Bug Depends on: | 283039 | ||
| Bug Blocks: | |||
David Kilzer (:ddkilzer)
Work around compiler bug in TypeCastsCocoa.mm test from TestWTF.
In TestWTF.TypeCastsCocoa.dynamic_objc_cast_RetainPtr (and TestWTF.TypeCastsCocoaARC.dynamic_objc_cast_RetainPtr), this declaration using `auto` causes the destructor for `object` to be called before `object.get()` when combined with the `WTFMove()` in the previous statement, resulting in `nullptr` being returned.
This was originally worked around in 291650@main for Bug 283039 by removing the `WTFMove()` call in the previous line, but then this code isn't testing `dynamic_objc_cast<T>(RetainPtr<U>&&)` anymore.
A better workaround is to replace `auto` with `RetainPtr<id>` so that we can add back the `WTFMove()` so the test calls the intended function.
```
TEST(TypeCastsCocoa, dynamic_objc_cast_RetainPtr)
{
[...]
@autoreleasepool {
auto object = adoptNS<id>([[NSString alloc] initWithFormat:@"%s", helloWorldCString]); // "Bad" auto
[...]
RetainPtr<NSArray> objectCastBad;
uintptr_t objectPtr2;
AUTORELEASEPOOL_FOR_ARC_DEBUG {
objectCastBad = dynamic_objc_cast<NSArray>(WTFMove(object));
objectPtr2 = reinterpret_cast<uintptr_t>(object.get()); // RetainPtr<id>::~RetainPtr() is called before object.get() here.
}
EXPECT_EQ(objectPtr, objectPtr2);
EXPECT_EQ(nil, objectCastBad.get());
EXPECT_EQ(1L, CFGetRetainCount((CFTypeRef)objectPtr2));
}
[...]
}
```
| Attachments | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Radar WebKit Bug Importer
<rdar://problem/148299583>
David Kilzer (:ddkilzer)
Pull request: https://github.com/WebKit/WebKit/pull/43373
EWS
Committed 293007@main (89cb37b46594): <https://commits.webkit.org/293007@main>
Reviewed commits have been landed. Closing PR #43373 and removing active labels.