[LLVMbugs] [Bug 15324] New: Add -Wobjc-self-assignment for "cannot assign to 'self'" warnings

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Feb 21 12:13:03 PST 2013


http://llvm.org/bugs/show_bug.cgi?id=15324

            Bug ID: 15324
           Summary: Add -Wobjc-self-assignment for "cannot assign to
                    'self'" warnings
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: arthur.j.odwyer at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

cat >test.m <<EOF
#import <Foundation/Foundation.h>
@interface A : NSObject
+(void)classmethod;
-(void)instancemethod;
@end

@implementation A
+(void) classmethod {
    self = nil;
}
-(void) instancemethod {
    self = nil;
}
@end
EOF

clang -fobjc-arc -c test.m
    test.m:9:10: error: cannot assign to 'self' in a class method
        self = nil;
        ~~~~ ^
    test.m:12:10: error: cannot assign to 'self' outside of a method in the
init family
        self = nil;
        ~~~~ ^
    2 errors generated.

clang -Weverything -c test.m
    (no diagnostics produced)

I suggested over at bug 9824 that warning on dead writes could suffice to
diagnose this problematic code in non-ARC mode. (There's a motivating example
over there as well.) However, it was suggested that I also file a new issue for
this potentially simpler fix.

I propose that Clang add a flag named something like "-Wobjc-self-assignment",
place both of the existing ARC diagnostics under that flag, and allow the user
to enable the flag in non-ARC mode (possibly, but not necessarily, combined
with -Werror).

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130221/8bc9de3d/attachment.html>


More information about the llvm-bugs mailing list