]> granicus.if.org Git - clang/commitdiff
allow implementations of deprecated functions to use deprecated symbols.
authorChris Lattner <sabre@nondot.org>
Sun, 15 Feb 2009 01:38:09 +0000 (01:38 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 15 Feb 2009 01:38:09 +0000 (01:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64572 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/Sema/attr-deprecated.c

index ef4ae54b86f2070bb7d59031c0a2c096cf3af7bc..43ed22a48b959a6768540d5bf646facb2ac8f4f7 100644 (file)
@@ -752,10 +752,16 @@ Sema::ActOnDeclarationNameExpr(Scope *S, SourceLocation Loc,
                                   false, false, SS));
   ValueDecl *VD = cast<ValueDecl>(D);
 
-  // check if referencing an identifier with __attribute__((deprecated)).
-  if (VD->getAttr<DeprecatedAttr>())
-    ExprError(Diag(Loc, diag::warn_deprecated) << VD->getDeclName());
-
+  // Check if referencing an identifier with __attribute__((deprecated)).
+  if (VD->getAttr<DeprecatedAttr>()) {
+    // If this reference happens *in* a deprecated function or method, don't
+    // warn.  Implementing deprecated stuff requires referencing depreated
+    // stuff.
+    NamedDecl *ND = getCurFunctionOrMethodDecl();
+    if (ND == 0 || !ND->getAttr<DeprecatedAttr>())
+      Diag(Loc, diag::warn_deprecated) << VD->getDeclName();
+  }
+  
   if (VarDecl *Var = dyn_cast<VarDecl>(VD)) {
     if (Var->isDeclaredInCondition() && Var->getType()->isScalarType()) {
       Scope *CheckS = S;
index dfe01dc71007c58c5b1b9f583e0a257162a20042..ada06f01e5e8a82e8455ee0de2005a3cf75c4e45 100644 (file)
@@ -29,6 +29,6 @@ int old_fn();
 int (*fn_ptr)() = old_fn; // expected-warning {{'old_fn' is deprecated}}
 
 int old_fn() {
-  return old_fn()+1;  // expected-warning {{'old_fn' is deprecated}}
+  return old_fn()+1;  // no warning, deprecated functions can use deprecated symbols.
 }