diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2010-10-06 23:12:32 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2010-10-06 23:12:32 +0000 |
commit | c784dc1caf0df288a383700f7b57772103b3adab (patch) | |
tree | fc6a5ca7d766c55ad2b1eed3316daeba3ea1b17f /lib/Sema/SemaDeclAttr.cpp | |
parent | 4895b9cf34b26b20e674a88fa8104489e1d06812 (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.cpp | 22 |
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) { |