Change the behavior of ibaction attributes to be attached to methods, not ivars.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96562 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
index bb47ae7..ef82d53 100644
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/lib/Sema/SemaDeclAttr.cpp
@@ -225,29 +225,38 @@
S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
}
-static void HandleIBAttr(Decl *d, const AttributeList &Attr, Sema &S) {
+static void HandleIBAction(Decl *d, const AttributeList &Attr, Sema &S) {
// check the attribute arguments.
if (Attr.getNumArgs() > 0) {
S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
return;
}
- // The IBOutlet/IBAction attributes only apply to instance variables of
+ // The IBAction attributes only apply to instance methods.
+ if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(d))
+ if (MD->isInstanceMethod()) {
+ d->addAttr(::new (S.Context) IBActionAttr());
+ return;
+ }
+
+ S.Diag(Attr.getLoc(), diag::err_attribute_ibaction) << Attr.getName();
+}
+
+static void HandleIBOutlet(Decl *d, const AttributeList &Attr, Sema &S) {
+ // check the attribute arguments.
+ if (Attr.getNumArgs() > 0) {
+ S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
+ return;
+ }
+
+ // The IBOutlet attributes only apply to instance variables of
// Objective-C classes.
if (isa<ObjCIvarDecl>(d) || isa<ObjCPropertyDecl>(d)) {
- switch (Attr.getKind()) {
- case AttributeList::AT_IBAction:
- d->addAttr(::new (S.Context) IBActionAttr());
- break;
- case AttributeList::AT_IBOutlet:
- d->addAttr(::new (S.Context) IBOutletAttr());
- break;
- default:
- llvm_unreachable("Invalid IB attribute");
- }
+ d->addAttr(::new (S.Context) IBOutletAttr());
+ return;
}
- else
- S.Diag(Attr.getLoc(), diag::err_attribute_ib) << Attr.getName();
+
+ S.Diag(Attr.getLoc(), diag::err_attribute_iboutlet) << Attr.getName();
}
static void HandleNonNullAttr(Decl *d, const AttributeList &Attr, Sema &S) {
@@ -1745,8 +1754,8 @@
// FIXME: Try to deal with other __declspec attributes!
return;
switch (Attr.getKind()) {
- case AttributeList::AT_IBAction:
- case AttributeList::AT_IBOutlet: HandleIBAttr (D, Attr, S); break;
+ case AttributeList::AT_IBAction: HandleIBAction(D, Attr, S); break;
+ case AttributeList::AT_IBOutlet: HandleIBOutlet(D, Attr, S); break;
case AttributeList::AT_address_space:
case AttributeList::AT_objc_gc:
case AttributeList::AT_vector_size: