Implement rdar://6756623 - use of deprecated type in deprecated typedef should not warn
llvm-svn: 85073
This commit is contained in:
parent
e24b16205f
commit
b7df3c66c8
|
@ -1583,7 +1583,8 @@ public:
|
|||
//===--------------------------------------------------------------------===//
|
||||
// Expression Parsing Callbacks: SemaExpr.cpp.
|
||||
|
||||
bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc);
|
||||
bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
|
||||
bool IgnoreDeprecated = false);
|
||||
bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD,
|
||||
ObjCMethodDecl *Getter,
|
||||
SourceLocation Loc);
|
||||
|
|
|
@ -37,20 +37,24 @@ using namespace clang;
|
|||
/// used, or produce an error (and return true) if a C++0x deleted
|
||||
/// function is being used.
|
||||
///
|
||||
/// If IgnoreDeprecated is set to true, this should not want about deprecated
|
||||
/// decls.
|
||||
///
|
||||
/// \returns true if there was an error (this declaration cannot be
|
||||
/// referenced), false otherwise.
|
||||
bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc) {
|
||||
///
|
||||
bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
|
||||
bool IgnoreDeprecated) {
|
||||
// See if the decl is deprecated.
|
||||
if (D->getAttr<DeprecatedAttr>()) {
|
||||
// Implementing deprecated stuff requires referencing deprecated
|
||||
// stuff. Don't warn if we are implementing a deprecated
|
||||
// construct.
|
||||
bool isSilenced = false;
|
||||
// stuff. Don't warn if we are implementing a deprecated construct.
|
||||
bool isSilenced = IgnoreDeprecated;
|
||||
|
||||
if (NamedDecl *ND = getCurFunctionOrMethodDecl()) {
|
||||
// If this reference happens *in* a deprecated function or method, don't
|
||||
// warn.
|
||||
isSilenced = ND->getAttr<DeprecatedAttr>();
|
||||
isSilenced |= ND->getAttr<DeprecatedAttr>() != 0;
|
||||
|
||||
// If this is an Objective-C method implementation, check to see if the
|
||||
// method was deprecated on the declaration, not the definition.
|
||||
|
|
|
@ -67,6 +67,16 @@ static bool isOmittedBlockReturnType(const Declarator &D) {
|
|||
return false;
|
||||
}
|
||||
|
||||
/// isDeclaratorDeprecated - Return true if the declarator is deprecated.
|
||||
/// We do not want to warn about use of deprecated types (e.g. typedefs) when
|
||||
/// defining a declaration that is itself deprecated.
|
||||
static bool isDeclaratorDeprecated(const Declarator &D) {
|
||||
for (const AttributeList *AL = D.getAttributes(); AL; AL = AL->getNext())
|
||||
if (AL->getKind() == AttributeList::AT_deprecated)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// \brief Convert the specified declspec to the appropriate type
|
||||
/// object.
|
||||
/// \param D the declarator containing the declaration specifier.
|
||||
|
@ -237,7 +247,8 @@ static QualType ConvertDeclSpecToType(Declarator &TheDeclarator, Sema &TheSema){
|
|||
}
|
||||
|
||||
// If the type is deprecated or unavailable, diagnose it.
|
||||
TheSema.DiagnoseUseOfDecl(D, DS.getTypeSpecTypeLoc());
|
||||
TheSema.DiagnoseUseOfDecl(D, DS.getTypeSpecTypeLoc(),
|
||||
isDeclaratorDeprecated(TheDeclarator));
|
||||
|
||||
assert(DS.getTypeSpecWidth() == 0 && DS.getTypeSpecComplex() == 0 &&
|
||||
DS.getTypeSpecSign() == 0 && "No qualifiers on tag names!");
|
||||
|
@ -298,15 +309,18 @@ static QualType ConvertDeclSpecToType(Declarator &TheDeclarator, Sema &TheSema){
|
|||
TheDeclarator.setInvalidType(true);
|
||||
|
||||
// If the type is deprecated or unavailable, diagnose it.
|
||||
TheSema.DiagnoseUseOfDecl(TDT->getDecl(), DS.getTypeSpecTypeLoc());
|
||||
TheSema.DiagnoseUseOfDecl(TDT->getDecl(), DS.getTypeSpecTypeLoc(),
|
||||
isDeclaratorDeprecated(TheDeclarator));
|
||||
} else if (ObjCInterfaceType *OIT = dyn_cast<ObjCInterfaceType>(Result)) {
|
||||
// If the type is deprecated or unavailable, diagnose it.
|
||||
TheSema.DiagnoseUseOfDecl(OIT->getDecl(), DS.getTypeSpecTypeLoc());
|
||||
TheSema.DiagnoseUseOfDecl(OIT->getDecl(), DS.getTypeSpecTypeLoc(),
|
||||
isDeclaratorDeprecated(TheDeclarator));
|
||||
} else if (ObjCObjectPointerType *DPT =
|
||||
dyn_cast<ObjCObjectPointerType>(Result)) {
|
||||
// If the type is deprecated or unavailable, diagnose it.
|
||||
if (ObjCInterfaceDecl *D = DPT->getInterfaceDecl())
|
||||
TheSema.DiagnoseUseOfDecl(D, DS.getTypeSpecTypeLoc());
|
||||
TheSema.DiagnoseUseOfDecl(D, DS.getTypeSpecTypeLoc(),
|
||||
isDeclaratorDeprecated(TheDeclarator));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -49,3 +49,9 @@ struct bar_dep __attribute__((deprecated,
|
|||
|
||||
struct bar_dep *test3; // expected-warning {{'bar_dep' is deprecated}}
|
||||
|
||||
|
||||
// These should not warn because the actually declaration itself is deprecated.
|
||||
// rdar://6756623
|
||||
foo_dep *test4 __attribute__((deprecated));
|
||||
struct bar_dep *test5 __attribute__((deprecated));
|
||||
|
||||
|
|
Loading…
Reference in New Issue