diff options
author | Ted Kremenek <kremenek@apple.com> | 2011-09-29 07:02:25 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2011-09-29 07:02:25 +0000 |
commit | 2f041d0b12aa87f3345e5fb2e38fefba30c5bff3 (patch) | |
tree | 2e3410c729561d70f52df47e4febab33b43175f4 /lib/Sema/SemaDeclAttr.cpp | |
parent | 4cd5791f4aa6deb572979bb38c1deedbc155efe0 (diff) |
Like IBOutletCollection, it only makes sense to apply the IBOutlet annotation to Objective-C object types. Fixes <rdar://problem/10142685>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140778 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDeclAttr.cpp')
-rw-r--r-- | lib/Sema/SemaDeclAttr.cpp | 56 |
1 files changed, 31 insertions, 25 deletions
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 6e0dc8f4a9..435507f9d7 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -753,19 +753,41 @@ static void handleIBAction(Sema &S, Decl *D, const AttributeList &Attr) { S.Diag(Attr.getLoc(), diag::warn_attribute_ibaction) << Attr.getName(); } +static bool checkIBOutletCommon(Sema &S, Decl *D, const AttributeList &Attr) { + // The IBOutlet/IBOutletCollection attributes only apply to instance + // variables or properties of Objective-C classes. The outlet must also + // have an object reference type. + if (const ObjCIvarDecl *VD = dyn_cast<ObjCIvarDecl>(D)) { + if (!VD->getType()->getAs<ObjCObjectPointerType>()) { + S.Diag(Attr.getLoc(), diag::err_iboutlet_object_type) + << Attr.getName() << VD->getType() << 0; + return false; + } + } + else if (const ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(D)) { + if (!PD->getType()->getAs<ObjCObjectPointerType>()) { + S.Diag(Attr.getLoc(), diag::err_iboutlet_object_type) + << Attr.getName() << PD->getType() << 1; + return false; + } + } + else { + S.Diag(Attr.getLoc(), diag::warn_attribute_iboutlet) << Attr.getName(); + return false; + } + + return true; +} + static void handleIBOutlet(Sema &S, Decl *D, const AttributeList &Attr) { // check the attribute arguments. if (!checkAttributeNumArgs(S, Attr, 0)) return; - - // The IBOutlet attributes only apply to instance variables of - // Objective-C classes. - if (isa<ObjCIvarDecl>(D) || isa<ObjCPropertyDecl>(D)) { - D->addAttr(::new (S.Context) IBOutletAttr(Attr.getRange(), S.Context)); + + if (!checkIBOutletCommon(S, D, Attr)) return; - } - S.Diag(Attr.getLoc(), diag::warn_attribute_iboutlet) << Attr.getName(); + D->addAttr(::new (S.Context) IBOutletAttr(Attr.getRange(), S.Context)); } static void handleIBOutletCollection(Sema &S, Decl *D, @@ -777,25 +799,9 @@ static void handleIBOutletCollection(Sema &S, Decl *D, return; } - // The IBOutletCollection attributes only apply to instance variables of - // Objective-C classes. - if (!(isa<ObjCIvarDecl>(D) || isa<ObjCPropertyDecl>(D))) { - S.Diag(Attr.getLoc(), diag::warn_attribute_iboutlet) << Attr.getName(); + if (!checkIBOutletCommon(S, D, Attr)) return; - } - if (const ValueDecl *VD = dyn_cast<ValueDecl>(D)) - if (!VD->getType()->getAs<ObjCObjectPointerType>()) { - S.Diag(Attr.getLoc(), diag::err_iboutletcollection_object_type) - << VD->getType() << 0; - return; - } - if (const ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(D)) - if (!PD->getType()->getAs<ObjCObjectPointerType>()) { - S.Diag(Attr.getLoc(), diag::err_iboutletcollection_object_type) - << PD->getType() << 1; - return; - } - + IdentifierInfo *II = Attr.getParameterName(); if (!II) II = &S.Context.Idents.get("id"); |