mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-26 02:46:08 +00:00
c - Enumerators may inherit the deprecated/unavailable
attributes from the enumeration type. // rdar://10201690 llvm-svn: 140800
This commit is contained in:
parent
196ebceb14
commit
d71061298c
@ -2222,7 +2222,8 @@ public:
|
|||||||
|
|
||||||
bool CanUseDecl(NamedDecl *D);
|
bool CanUseDecl(NamedDecl *D);
|
||||||
bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
|
bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
|
||||||
const ObjCInterfaceDecl *UnknownObjCClass = 0);
|
const ObjCInterfaceDecl *UnknownObjCClass = 0,
|
||||||
|
const EnumDecl *EnumeratorEnumDecl = 0);
|
||||||
std::string getDeletedOrUnavailableSuffix(const FunctionDecl *FD);
|
std::string getDeletedOrUnavailableSuffix(const FunctionDecl *FD);
|
||||||
bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD,
|
bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD,
|
||||||
ObjCMethodDecl *Getter,
|
ObjCMethodDecl *Getter,
|
||||||
|
@ -69,7 +69,8 @@ bool Sema::CanUseDecl(NamedDecl *D) {
|
|||||||
/// referenced), false otherwise.
|
/// referenced), false otherwise.
|
||||||
///
|
///
|
||||||
bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
|
bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
|
||||||
const ObjCInterfaceDecl *UnknownObjCClass) {
|
const ObjCInterfaceDecl *UnknownObjCClass,
|
||||||
|
const EnumDecl *EnumeratorEnumDecl) {
|
||||||
if (getLangOptions().CPlusPlus && isa<FunctionDecl>(D)) {
|
if (getLangOptions().CPlusPlus && isa<FunctionDecl>(D)) {
|
||||||
// If there were any diagnostics suppressed by template argument deduction,
|
// If there were any diagnostics suppressed by template argument deduction,
|
||||||
// emit them now.
|
// emit them now.
|
||||||
@ -106,11 +107,12 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
|
|||||||
|
|
||||||
// See if this declaration is unavailable or deprecated.
|
// See if this declaration is unavailable or deprecated.
|
||||||
std::string Message;
|
std::string Message;
|
||||||
switch (D->getAvailability(&Message)) {
|
AvailabilityResult Result = D->getAvailability(&Message);
|
||||||
|
switch (Result) {
|
||||||
case AR_Available:
|
case AR_Available:
|
||||||
case AR_NotYetIntroduced:
|
case AR_NotYetIntroduced:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AR_Deprecated:
|
case AR_Deprecated:
|
||||||
EmitDeprecationWarning(D, Message, Loc, UnknownObjCClass);
|
EmitDeprecationWarning(D, Message, Loc, UnknownObjCClass);
|
||||||
break;
|
break;
|
||||||
@ -134,9 +136,17 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Warn if this is used but marked unused.
|
// 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();
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ enum __attribute__((deprecated)) Test20 {
|
|||||||
void test20() {
|
void test20() {
|
||||||
enum Test20 f; // expected-warning {{'Test20' is deprecated}}
|
enum Test20 f; // expected-warning {{'Test20' is deprecated}}
|
||||||
f = test20_a; // expected-warning {{'test20_a' is deprecated}}
|
f = test20_a; // expected-warning {{'test20_a' is deprecated}}
|
||||||
f = test20_b;
|
f = test20_b; // expected-warning {{'Test20' is deprecated}}
|
||||||
}
|
}
|
||||||
|
|
||||||
char test21[__has_feature(attribute_deprecated_with_message) ? 1 : -1];
|
char test21[__has_feature(attribute_deprecated_with_message) ? 1 : -1];
|
||||||
|
@ -26,3 +26,24 @@ void unavail(void) {
|
|||||||
void (*fp)() = &bar;
|
void (*fp)() = &bar;
|
||||||
double (*fp4)(double) = dfoo;
|
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}}
|
||||||
|
}
|
||||||
|
@ -198,7 +198,7 @@ namespace test6 {
|
|||||||
};
|
};
|
||||||
void testA() {
|
void testA() {
|
||||||
A x; // expected-warning {{'A' is deprecated}}
|
A x; // expected-warning {{'A' is deprecated}}
|
||||||
x = a0;
|
x = a0; // expected-warning {{'A' is deprecated}}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum B {
|
enum B {
|
||||||
@ -218,7 +218,7 @@ namespace test6 {
|
|||||||
};
|
};
|
||||||
void testC() {
|
void testC() {
|
||||||
C<int>::Enum x; // expected-warning {{'Enum' is deprecated}}
|
C<int>::Enum x; // expected-warning {{'Enum' is deprecated}}
|
||||||
x = C<int>::c0;
|
x = C<int>::c0; // expected-warning {{'Enum' is deprecated}}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> struct D {
|
template <class T> struct D {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user