]> granicus.if.org Git - clang/commitdiff
It's okay to refer to non-type template parameters anywhere they are
authorDouglas Gregor <dgregor@apple.com>
Tue, 27 Apr 2010 21:10:04 +0000 (21:10 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 27 Apr 2010 21:10:04 +0000 (21:10 +0000)
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

lib/Sema/SemaExpr.cpp
test/SemaCXX/local-classes.cpp

index 997b8f8dcb182902ab13541f2a5cb7bfc3609fb7..89a329140facaa012b94ff186f853fb728ebd8d7 100644 (file)
@@ -459,7 +459,10 @@ Sema::BuildDeclRefExpr(ValueDecl *D, QualType Ty, SourceLocation Loc,
   }
 
   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)
index 6799e58e954e08bf05a59c6d295b187e0fd44238..500b2197ef35f1016b2a2cecc5d23613229a6950 100644 (file)
@@ -30,3 +30,12 @@ namespace PR6383 {
     compare_and_set2 (false, gross);
   }
 }
+
+namespace Templates {
+  template<int Value>
+  void f() {
+    struct Inner {
+      static int getValue() { return Value; }
+    };
+  }
+}