bool CanUseDecl(NamedDecl *D);
bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
- const ObjCInterfaceDecl *UnknownObjCClass = 0);
+ const ObjCInterfaceDecl *UnknownObjCClass = 0,
+ const EnumDecl *EnumeratorEnumDecl = 0);
std::string getDeletedOrUnavailableSuffix(const FunctionDecl *FD);
bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD,
ObjCMethodDecl *Getter,
/// 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.
// 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;
}
// 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;
}
void (*fp)() = &bar;
double (*fp4)(double) = dfoo;
}
+
+// rdar://10201690
+enum foo {
+ a = 1,
+ b __attribute__((deprecated())) = 2,
+ c = 3
+}__attribute__((deprecated()));
+
+enum fee { // expected-note 2 {{declaration has been explicitly marked unavailable here}}
+ r = 1,
+ s = 2,
+ t = 3
+}__attribute__((unavailable()));
+
+enum fee f() { // expected-error {{error: 'fee' is unavailable}}
+ int i = a; // expected-warning {{'foo' is deprecated }}
+
+ i = b; // expected-warning {{'b' is deprecated}}
+
+ return r; // expected-error {{'fee' is unavailable}}
+}