Improvements to decltype. We now don't crash anymore when the expr is an overloaded function decl.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74472 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index a53e420..cbd4f58 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -406,6 +406,9 @@
 
   QualType getQualifiedNameType(const CXXScopeSpec &SS, QualType T);
 
+  QualType BuildTypeofExprType(Expr *E);
+  QualType BuildDecltypeType(Expr *E);
+  
   //===--------------------------------------------------------------------===//
   // Symbol table / Decl tracking callbacks: SemaDecl.cpp.
   //
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp
index aed3489..f05323b 100644
--- a/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/lib/Sema/SemaTemplateInstantiate.cpp
@@ -530,7 +530,7 @@
   if (E.isInvalid())
     return QualType();
 
-  return SemaRef.Context.getTypeOfExprType(E.takeAs<Expr>());
+  return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
 }
 
 QualType 
@@ -555,7 +555,7 @@
   if (E.isInvalid())
     return QualType();
   
-  return SemaRef.Context.getDecltypeType(E.takeAs<Expr>());
+  return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
 }
 
 QualType 
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp
index 1c67dae..c0b4e9f 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -242,7 +242,11 @@
     Expr *E = static_cast<Expr *>(DS.getTypeRep());
     assert(E && "Didn't get an expression for decltype?");
     // TypeQuals handled by caller.
-    Result = Context.getDecltypeType(E);
+    Result = BuildDecltypeType(E);
+    if (Result.isNull()) {
+      Result = Context.IntTy;
+      isInvalid = true;
+    }
     break;
   }
   case DeclSpec::TST_auto: {
@@ -1463,3 +1467,16 @@
     = static_cast<NestedNameSpecifier *>(SS.getScopeRep());
   return Context.getQualifiedNameType(NNS, T);
 }
+
+QualType Sema::BuildTypeofExprType(Expr *E) {
+  return Context.getTypeOfExprType(E);
+}
+
+QualType Sema::BuildDecltypeType(Expr *E) {
+  if (E->getType() == Context.OverloadTy) {
+    Diag(E->getLocStart(), 
+         diag::err_cannot_determine_declared_type_of_overloaded_function);
+    return QualType();
+  }
+  return Context.getDecltypeType(E);
+}