summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDeclAttr.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2011-09-29 07:02:25 +0000
committerTed Kremenek <kremenek@apple.com>2011-09-29 07:02:25 +0000
commit7fd172361945131ee5d7d7766609e21296fa64a5 (patch)
treeef3ea0a0ec8b0c36aa52e7186821a38eadd0021d /clang/lib/Sema/SemaDeclAttr.cpp
parent6e302b2e6e8912a2e92ee035b6412a5d098ade1c (diff)
downloadbcm5719-llvm-7fd172361945131ee5d7d7766609e21296fa64a5.tar.gz
bcm5719-llvm-7fd172361945131ee5d7d7766609e21296fa64a5.zip
Like IBOutletCollection, it only makes sense to apply the IBOutlet annotation to Objective-C object types. Fixes <rdar://problem/10142685>.
llvm-svn: 140778
Diffstat (limited to 'clang/lib/Sema/SemaDeclAttr.cpp')
-rw-r--r--clang/lib/Sema/SemaDeclAttr.cpp56
1 files changed, 31 insertions, 25 deletions
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 6e0dc8f4a98..435507f9d78 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/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");
OpenPOWER on IntegriCloud