//===--------------------------------------------------------------------===//
// 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);
/// 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.
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.
}
// 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!");
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));
}