[cfe-commits] r102466 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaCXX/local-classes.cpp

Douglas Gregor dgregor at apple.com
Tue Apr 27 14:10:04 PDT 2010


Author: dgregor
Date: Tue Apr 27 16:10:04 2010
New Revision: 102466

URL: http://llvm.org/viewvc/llvm-project?rev=102466&view=rev
Log:
It's okay to refer to non-type template parameters anywhere they are
visible. Fixes the remaining two failures in Boost.ScopeExit.

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaCXX/local-classes.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=102466&r1=102465&r2=102466&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Apr 27 16:10:04 2010
@@ -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)

Modified: cfe/trunk/test/SemaCXX/local-classes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/local-classes.cpp?rev=102466&r1=102465&r2=102466&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/local-classes.cpp (original)
+++ cfe/trunk/test/SemaCXX/local-classes.cpp Tue Apr 27 16:10:04 2010
@@ -30,3 +30,12 @@
     compare_and_set2 (false, gross);
   }
 }
+
+namespace Templates {
+  template<int Value>
+  void f() {
+    struct Inner {
+      static int getValue() { return Value; }
+    };
+  }
+}





More information about the cfe-commits mailing list