Refactor the deprecated and unavailable checks into a new
DiagnoseUseOfDeprecatedDecl method.  This ensures that they
are treated consistently.  This gets us 'unavailable' support
on a few new types of decls, and makes sure we consistently
silence deprecated when the caller is also deprecated.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64612 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 43ed22a..3143fc7 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -26,6 +26,25 @@
 #include "clang/Parse/Scope.h"
 using namespace clang;
 
+
+/// DiagnoseUseOfDeprecatedDeclImpl - If the specified decl is deprecated or
+// unavailable, emit the corresponding diagnostics. 
+void Sema::DiagnoseUseOfDeprecatedDeclImpl(NamedDecl *D, SourceLocation Loc) {
+  // See if the decl is deprecated.
+  if (D->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) << D->getDeclName();
+  }
+
+  // See if hte decl is unavailable.
+  if (D->getAttr<UnavailableAttr>())
+    Diag(Loc, diag::warn_unavailable) << D->getDeclName();
+}
+
 //===----------------------------------------------------------------------===//
 //  Standard Promotions and Conversions
 //===----------------------------------------------------------------------===//
@@ -89,9 +108,7 @@
 
 // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
 // will warn if the resulting type is not a POD type.
-void Sema::DefaultVariadicArgumentPromotion(Expr *&Expr, VariadicCallType CT)
-
-{
+void Sema::DefaultVariadicArgumentPromotion(Expr *&Expr, VariadicCallType CT) {
   DefaultArgumentPromotion(Expr);
   
   if (!Expr->getType()->isPODType()) {
@@ -145,10 +162,14 @@
   // lhs == rhs check. Also, for conversion purposes, we ignore any
   // qualifiers.  For example, "const float" and "float" are
   // equivalent.
-  if (lhs->isPromotableIntegerType()) lhs = Context.IntTy;
-  else                                lhs = lhs.getUnqualifiedType();
-  if (rhs->isPromotableIntegerType()) rhs = Context.IntTy;
-  else                                rhs = rhs.getUnqualifiedType();
+  if (lhs->isPromotableIntegerType())
+    lhs = Context.IntTy;
+  else
+    lhs = lhs.getUnqualifiedType();
+  if (rhs->isPromotableIntegerType())
+    rhs = Context.IntTy;
+  else
+    rhs = rhs.getUnqualifiedType();
 
   // If both types are identical, no conversion is needed.
   if (lhs == rhs)
@@ -223,14 +244,10 @@
     // We have two real floating types, float/complex combos were handled above.
     // Convert the smaller operand to the bigger result.
     int result = Context.getFloatingTypeOrder(lhs, rhs);
-    
-    if (result > 0) { // convert the rhs
+    if (result > 0) // convert the rhs
       return lhs;
-    }
-    if (result < 0) { // convert the lhs
-      return rhs;
-    }
-    assert(0 && "Sema::UsualArithmeticConversionsType(): illegal float comparison");
+    assert(result < 0 && "illegal float comparison");
+    return rhs;   // convert the lhs
   }
   if (lhs->isComplexIntegerType() || rhs->isComplexIntegerType()) {
     // Handle GCC complex int extension.
@@ -239,10 +256,8 @@
 
     if (lhsComplexInt && rhsComplexInt) {
       if (Context.getIntegerTypeOrder(lhsComplexInt->getElementType(), 
-                                      rhsComplexInt->getElementType()) >= 0) {
-        // convert the rhs
-        return lhs;
-      }
+                                      rhsComplexInt->getElementType()) >= 0)
+        return lhs; // convert the rhs
       return rhs;
     } else if (lhsComplexInt && rhs->isIntegerType()) {
       // convert the rhs to the lhs complex type.
@@ -753,14 +768,7 @@
   ValueDecl *VD = cast<ValueDecl>(D);
 
   // 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();
-  }
+  DiagnoseUseOfDeprecatedDecl(VD, Loc);
   
   if (VarDecl *Var = dyn_cast<VarDecl>(VD)) {
     if (Var->isDeclaredInCondition() && Var->getType()->isScalarType()) {
@@ -1510,6 +1518,7 @@
   return VT; // should never get here (a typedef type should always be found).
 }
 
+
 /// constructSetterName - Return the setter name for the given
 /// identifier, i.e. "set" + Name where the initial character of Name
 /// has been capitalized.