<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Add -Wobjc-self-assignment for "cannot assign to 'self'" warnings"
   href="http://llvm.org/bugs/show_bug.cgi?id=15324">15324</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Add -Wobjc-self-assignment for "cannot assign to 'self'" warnings
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Frontend
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>arthur.j.odwyer@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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 <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - add -Wunused-but-set-variable"
   href="show_bug.cgi?id=9824">bug 9824</a> 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).</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>