Make sure to calculate value-dependence correctly when deal with ICEs.  
(Actually, this isn't precisely correct, but it doesn't make 
sense to query whether an expression that isn't an ICE is 
value-dependent anyway.)



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73179 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index da32d4e..1abd5fb 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -1177,7 +1177,12 @@
       ValueDependent = true;
     //    - a constant with integral or enumeration type and is
     //      initialized with an expression that is value-dependent
-    //      (FIXME!).
+    else if (const VarDecl *Dcl = dyn_cast<VarDecl>(VD)) {
+      if (Dcl->getType().getCVRQualifiers() == QualType::Const &&
+          Dcl->getInit()) {
+        ValueDependent = Dcl->getInit()->isValueDependent();
+      }
+    }
   }
 
   return Owned(BuildDeclRefExpr(VD, VD->getType().getNonReferenceType(), Loc,
diff --git a/test/SemaTemplate/instantiate-declref-ice.cpp b/test/SemaTemplate/instantiate-declref-ice.cpp
new file mode 100644
index 0000000..21ee872
--- /dev/null
+++ b/test/SemaTemplate/instantiate-declref-ice.cpp
@@ -0,0 +1,7 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+template<int i> struct x {
+  static const int j = i;
+  x<j>* y;
+};
+