From: Ted Kremenek Date: Wed, 23 Jul 2008 18:21:36 +0000 (+0000) Subject: Properly skip IBOutlets when checking for unused ivars. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cc87ba2b950cfef2ef43019627330975a7daf73a;p=clang Properly skip IBOutlets when checking for unused ivars. 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 --- diff --git a/lib/Analysis/CheckObjCUnusedIVars.cpp b/lib/Analysis/CheckObjCUnusedIVars.cpp index d074dde8a3..d536ea4bdb 100644 --- a/lib/Analysis/CheckObjCUnusedIVars.cpp +++ b/lib/Analysis/CheckObjCUnusedIVars.cpp @@ -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() == 0) + + // Skip IB Outlets. + if (ID->getAttr()) 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 index 0000000000..c29e243fc3 --- /dev/null +++ b/test/Analysis/unused-ivars.m @@ -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 +