diff options
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 5 | ||||
-rw-r--r-- | test/SemaCXX/local-classes.cpp | 9 |
2 files changed, 13 insertions, 1 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 997b8f8dcb..89a329140f 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -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) diff --git a/test/SemaCXX/local-classes.cpp b/test/SemaCXX/local-classes.cpp index 6799e58e95..500b2197ef 100644 --- a/test/SemaCXX/local-classes.cpp +++ b/test/SemaCXX/local-classes.cpp @@ -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; } + }; + } +} |