Fix PR4448.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74257 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp
index 188580d..fed03a8 100644
--- a/lib/Parse/ParseDeclCXX.cpp
+++ b/lib/Parse/ParseDeclCXX.cpp
@@ -365,14 +365,12 @@
   SourceLocation StartLoc = ConsumeToken();
   SourceLocation LParenLoc = Tok.getLocation();
   
-    
   if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after, 
                        "decltype")) {
     SkipUntil(tok::r_paren);
     return;
   }
   
-  
   // Parse the expression
   
   // C++0x [dcl.type.simple]p4:
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp
index 5e4fde7..0c78c71 100644
--- a/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/lib/Sema/SemaTemplateInstantiate.cpp
@@ -560,6 +560,11 @@
 QualType
 TemplateTypeInstantiator::InstantiateDecltypeType(const DecltypeType *T,
                                                   unsigned Quals) const {
+  // C++0x [dcl.type.simple]p4:
+  //   The operand of the decltype specifier is an unevaluated operand.
+  EnterExpressionEvaluationContext Unevaluated(SemaRef,
+                                               Action::Unevaluated);
+  
   Sema::OwningExprResult E 
     = SemaRef.InstantiateExpr(T->getUnderlyingExpr(), TemplateArgs);
 
diff --git a/lib/Sema/SemaTemplateInstantiateExpr.cpp b/lib/Sema/SemaTemplateInstantiateExpr.cpp
index aba2c99..65a35f9 100644
--- a/lib/Sema/SemaTemplateInstantiateExpr.cpp
+++ b/lib/Sema/SemaTemplateInstantiateExpr.cpp
@@ -119,6 +119,14 @@
       // FIXME: Clone the expression!
       return SemaRef.Owned(Arg.getAsExpr());
 
+    if (Arg.getKind() == TemplateArgument::Declaration) {
+      ValueDecl *VD = cast<ValueDecl>(Arg.getAsDecl());
+
+      // FIXME: Can VD ever have a dependent type?
+      return SemaRef.BuildDeclRefExpr(VD, VD->getType(), E->getLocation(), 
+                                      false, false);
+    }
+    
     assert(Arg.getKind() == TemplateArgument::Integral);
     QualType T = Arg.getIntegralType();
     if (T->isCharType() || T->isWideCharType())