Assigning retained object to both weak reference and regular reference warns you
| Originator: | ckrames1234 | ||
| Number: | rdar://11951049 | Date Originated: | 24-Jul-2012 09:12 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Apple clang version 4.0 (tags/Apple/clang-421.10.53) (based on LLVM 3.1svn) |
| Classification: | Other Bug | Reproducible: | Always |
24-Jul-2012 09:12 PM Aaron KRAMER:
Summary:
When assigning a retained object to a weak reference, the `arc-unsafe-retained-assign` warning is thrown, because the object will be released immediately after assignment. But if you assign this retained object to a weak reference *and* a normal reference in the same statement, the warning is stil thrown, even though the object will not be released immediately after assignment.
Steps to Reproduce:
Compile the following code with Clang with -fobjc-arc set:
__weak NSObject *weakRef;
NSObject *normalRef;
normalRef = weakRef = [[NSObject alloc] init];
Expected Results:
The code should compile with no warning.
Actual Results:
The following warning is printed:
warning: assigning retained object to weak variable; object will be released after assignment [-Warc-unsafe-retained-assign]
normalRef = weakRef = [[NSObject alloc] init];
^ ~~~~~~~~~~~~~~~~~~~~~~~
Regression:
The problem does not occur if the normal reference is assigned first, i.e.:
weakRef = normalRef = [[NSObject alloc] init];
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!