aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaDeclAttr.cpp
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2010-10-06 23:12:32 +0000
committerFariborz Jahanian <fjahanian@apple.com>2010-10-06 23:12:32 +0000
commitc784dc1caf0df288a383700f7b57772103b3adab (patch)
treefc6a5ca7d766c55ad2b1eed3316daeba3ea1b17f /lib/Sema/SemaDeclAttr.cpp
parent4895b9cf34b26b20e674a88fa8104489e1d06812 (diff)
Patch for adding message to unavailable attribute.
And its documentation. Finishes off // rdar: // 6734520. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@115862 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDeclAttr.cpp')
-rw-r--r--lib/Sema/SemaDeclAttr.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
index 3e1ced29a8..e9ee50fe75 100644
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/lib/Sema/SemaDeclAttr.cpp
@@ -929,12 +929,26 @@ static void HandleDeprecatedAttr(Decl *d, const AttributeList &Attr, Sema &S) {
static void HandleUnavailableAttr(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;
+ int noArgs = Attr.getNumArgs();
+ if (noArgs > 1) {
+ S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << "0 or 1";
return;
}
-
- d->addAttr(::new (S.Context) UnavailableAttr(Attr.getLoc(), S.Context));
+ // Handle the case where unavailable attribute has a text message.
+ StringLiteral *SE;
+ if (noArgs == 1) {
+ Expr *ArgExpr = static_cast<Expr *>(Attr.getArg(0));
+ SE = dyn_cast<StringLiteral>(ArgExpr);
+ if (!SE) {
+ S.Diag(ArgExpr->getLocStart(),
+ diag::err_attribute_not_string) << "unavailable";
+ return;
+ }
+ }
+ else
+ SE = StringLiteral::CreateEmpty(S.Context, 1);
+ d->addAttr(::new (S.Context) UnavailableAttr(Attr.getLoc(), S.Context,
+ SE->getString()));
}
static void HandleVisibilityAttr(Decl *d, const AttributeList &Attr, Sema &S) {