Add message to attribute(deprecated).
attribute(unavailable) to do next.
// rdar:// 6734520.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@115842 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp
index 9800db0..1376472 100644
--- a/lib/Sema/SemaDeclAttr.cpp
+++ b/lib/Sema/SemaDeclAttr.cpp
@@ -903,12 +903,28 @@
static void HandleDeprecatedAttr(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;
}
+ // Handle the case where deprecated 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) << "deprecated";
+ return;
+ }
+ }
+ else
+ SE = StringLiteral::CreateEmpty(S.Context, 1);
- d->addAttr(::new (S.Context) DeprecatedAttr(Attr.getLoc(), S.Context));
+ d->addAttr(::new (S.Context) DeprecatedAttr(Attr.getLoc(), S.Context,
+ SE->getString()));
}
static void HandleUnavailableAttr(Decl *d, const AttributeList &Attr, Sema &S) {
@@ -2536,20 +2552,30 @@
return;
DD.Triggered = true;
- Diag(DD.Loc, diag::warn_deprecated)
- << DD.DeprecationData.Decl->getDeclName();
+ if (strlen(DD.DeprecationData.Message))
+ Diag(DD.Loc, diag::warn_deprecated_message)
+ << DD.DeprecationData.Decl->getDeclName()
+ << DD.DeprecationData.Message;
+ else
+ Diag(DD.Loc, diag::warn_deprecated)
+ << DD.DeprecationData.Decl->getDeclName();
}
-void Sema::EmitDeprecationWarning(NamedDecl *D, SourceLocation Loc) {
+void Sema::EmitDeprecationWarning(NamedDecl *D, const char * Message,
+ SourceLocation Loc) {
// Delay if we're currently parsing a declaration.
if (ParsingDeclDepth) {
- DelayedDiagnostics.push_back(DelayedDiagnostic::makeDeprecation(Loc, D));
+ DelayedDiagnostics.push_back(DelayedDiagnostic::makeDeprecation(Loc, D,
+ Message));
return;
}
// Otherwise, don't warn if our current context is deprecated.
if (isDeclDeprecated(cast<Decl>(CurContext)))
return;
-
- Diag(Loc, diag::warn_deprecated) << D->getDeclName();
+ if (strlen(Message))
+ Diag(Loc, diag::warn_deprecated_message) << D->getDeclName()
+ << Message;
+ else
+ Diag(Loc, diag::warn_deprecated) << D->getDeclName();
}
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index 89ae18f..09502a4 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -1622,9 +1622,13 @@
// If the interface declared this method, and it was deprecated there,
// mark it deprecated here.
if (InterfaceMD)
- if (Attr *DA = InterfaceMD->getAttr<DeprecatedAttr>())
- ObjCMethod->addAttr(::new (Context) DeprecatedAttr(DA->getLocation(),
- Context));
+ if (Attr *DA = InterfaceMD->getAttr<DeprecatedAttr>()) {
+ StringLiteral *SE = StringLiteral::CreateEmpty(Context, 1);
+ ObjCMethod->addAttr(::new (Context)
+ DeprecatedAttr(DA->getLocation(),
+ Context,
+ SE->getString()));
+ }
return ObjCMethod;
}
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index ef21a27..d54a858 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -57,8 +57,10 @@
///
bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc) {
// See if the decl is deprecated.
- if (D->getAttr<DeprecatedAttr>()) {
- EmitDeprecationWarning(D, Loc);
+ if (const DeprecatedAttr *DA = D->getAttr<DeprecatedAttr>()) {
+ const char *Message =
+ DA->getMessage().empty() ? "" : DA->getMessage().data();
+ EmitDeprecationWarning(D, Message, Loc);
}
// See if the decl is unavailable