Properly skip IBOutlets when checking for unused ivars.

Refine the error message of unused ivars.
Added test case.

llvm-svn: 53957
This commit is contained in:
Ted Kremenek 2008-07-23 18:21:36 +00:00
parent 0cdba6b43e
commit 46abc7db6b
2 changed files with 16 additions and 4 deletions

View 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());
}

View File

@ -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