It's okay to refer to non-type template parameters anywhere they are
visible. Fixes the remaining two failures in Boost.ScopeExit.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102466 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 997b8f8..89a3291 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -459,7 +459,10 @@
   }
 
   if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
-    if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(CurContext)) {
+    if (isa<NonTypeTemplateParmDecl>(VD)) {
+      // Non-type template parameters can be referenced anywhere they are
+      // visible.
+    } else if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(CurContext)) {
       if (const FunctionDecl *FD = MD->getParent()->isLocalClass()) {
         if (VD->hasLocalStorage() && VD->getDeclContext() != CurContext) {
           Diag(Loc, diag::err_reference_to_local_var_in_enclosing_function)
diff --git a/test/SemaCXX/local-classes.cpp b/test/SemaCXX/local-classes.cpp
index 6799e58..500b219 100644
--- a/test/SemaCXX/local-classes.cpp
+++ b/test/SemaCXX/local-classes.cpp
@@ -30,3 +30,12 @@
     compare_and_set2 (false, gross);
   }
 }
+
+namespace Templates {
+  template<int Value>
+  void f() {
+    struct Inner {
+      static int getValue() { return Value; }
+    };
+  }
+}