]> granicus.if.org Git - clang/commitdiff
Properly skip IBOutlets when checking for unused ivars.
authorTed Kremenek <kremenek@apple.com>
Wed, 23 Jul 2008 18:21:36 +0000 (18:21 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 23 Jul 2008 18:21:36 +0000 (18:21 +0000)
Refine the error message of unused ivars.
Added test case.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53957 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/CheckObjCUnusedIVars.cpp
test/Analysis/unused-ivars.m [new file with mode: 0644]

index d074dde8a3c9bb6c5ed33769ccf1a815ba0a5af6..d536ea4bdbfad824ed0602bd749b470990098780 100644 (file)
@@ -57,8 +57,9 @@ void clang::CheckObjCUnusedIvar(ObjCImplementationDecl* D, BugReporter& BR) {
     // Ignore ivars that aren't private.
     if (ID->getAccessControl() != ObjCIvarDecl::Private)
       continue;
-    
-    if (ID->getAttr<IBOutletAttr>() == 0)
+
+    // Skip IB Outlets.
+    if (ID->getAttr<IBOutletAttr>())
       continue;
     
     M[ID] = Unused;
@@ -77,8 +78,9 @@ void clang::CheckObjCUnusedIvar(ObjCImplementationDecl* D, BugReporter& BR) {
     if (I->second == Unused) {
       
       std::ostringstream os;
-      os << "Private ivar '" << I->first->getName() << "' is never used.";
-      
+      os << "Instance variable '" << I->first->getName()
+         << "' in class '" << ID->getName() << "' is never used.";
+
       BR.EmitBasicReport("unused ivar",
                          os.str().c_str(), I->first->getLocation());
     }
diff --git a/test/Analysis/unused-ivars.m b/test/Analysis/unused-ivars.m
new file mode 100644 (file)
index 0000000..c29e243
--- /dev/null
@@ -0,0 +1,10 @@
+// RUN: clang -warn-objc-unused-ivars %s -verify
+
+@interface A
+{
+  @private int x; // expected-warning {{Instance variable 'x' in class 'A' is never used.}}
+}
+@end
+
+@implementation A @end
+