aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaExpr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Sema/SemaExpr.cpp')
-rw-r--r--lib/Sema/SemaExpr.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 2b67b4dc48..f9d34a7fa3 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -69,7 +69,8 @@ bool Sema::CanUseDecl(NamedDecl *D) {
/// referenced), false otherwise.
///
bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
- const ObjCInterfaceDecl *UnknownObjCClass) {
+ const ObjCInterfaceDecl *UnknownObjCClass,
+ const EnumDecl *EnumeratorEnumDecl) {
if (getLangOptions().CPlusPlus && isa<FunctionDecl>(D)) {
// If there were any diagnostics suppressed by template argument deduction,
// emit them now.
@@ -106,11 +107,12 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
// See if this declaration is unavailable or deprecated.
std::string Message;
- switch (D->getAvailability(&Message)) {
+ AvailabilityResult Result = D->getAvailability(&Message);
+ switch (Result) {
case AR_Available:
case AR_NotYetIntroduced:
break;
-
+
case AR_Deprecated:
EmitDeprecationWarning(D, Message, Loc, UnknownObjCClass);
break;
@@ -134,9 +136,17 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
}
// Warn if this is used but marked unused.
- if (D->hasAttr<UnusedAttr>())
+ if (D->hasAttr<UnusedAttr>() && !EnumeratorEnumDecl)
Diag(Loc, diag::warn_used_but_marked_unused) << D->getDeclName();
-
+ // For available enumerator, it will become unavailable/deprecated
+ // if its enum declaration is as such.
+ if (Result == AR_Available)
+ if (const EnumConstantDecl *ECD = dyn_cast<EnumConstantDecl>(D)) {
+ const DeclContext *DC = ECD->getDeclContext();
+ if (const EnumDecl *TheEnumDecl = dyn_cast<EnumDecl>(DC))
+ DiagnoseUseOfDecl(const_cast< EnumDecl *>(TheEnumDecl),
+ Loc, UnknownObjCClass, TheEnumDecl);
+ }
return false;
}