Fix the parser's updating of the template depth when parsing local templates and late-parsed templates.
This is a slight tweak of r180708; It avoids incrementing depth when non-template local classes nested within member templates of local classes are encountered.
This patch was LGTM'd by Doug http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20130506/079656.html and passed the regression tests that normally pass (i.e. excluding many Module and Index tests on Windows that fail regardless)
llvm-svn: 183620
diff --git a/clang/lib/Parse/ParseTemplate.cpp b/clang/lib/Parse/ParseTemplate.cpp
index 84b7df7..f55fcc0 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -1263,12 +1263,14 @@
Actions.ActOnReenterTemplateScope(getCurScope(), MD);
++CurTemplateDepthTracker;
} else if (CXXRecordDecl *MD = dyn_cast_or_null<CXXRecordDecl>(*II)) {
- bool ManageScope = MD->getDescribedClassTemplate() != 0;
+ bool IsClassTemplate = MD->getDescribedClassTemplate() != 0;
TemplateParamScopeStack.push_back(
- new ParseScope(this, Scope::TemplateParamScope, ManageScope));
+ new ParseScope(this, Scope::TemplateParamScope,
+ /*ManageScope*/IsClassTemplate));
Actions.ActOnReenterTemplateScope(getCurScope(),
MD->getDescribedClassTemplate());
- ++CurTemplateDepthTracker;
+ if (IsClassTemplate)
+ ++CurTemplateDepthTracker;
}
TemplateParamScopeStack.push_back(new ParseScope(this, Scope::DeclScope));
Actions.PushDeclContext(Actions.getCurScope(), *II);
diff --git a/clang/test/SemaTemplate/local-member-templates.cpp b/clang/test/SemaTemplate/local-member-templates.cpp
index 3cdf5df..847d483 100644
--- a/clang/test/SemaTemplate/local-member-templates.cpp
+++ b/clang/test/SemaTemplate/local-member-templates.cpp
@@ -74,3 +74,26 @@
Outer<int>::outer_mem(int, char); //expected-note{{in instantiation of}}
}
+
+namespace more_nested_local_templates {
+
+int test() {
+ struct Local {
+ template<class U> void foo(U u) {
+ struct Inner {
+ template<class A>
+ auto operator()(A a, U u2) -> U {
+ return u2;
+ };
+ };
+ Inner GL;
+ GL('a', u );
+ GL(3.14, u );
+ }
+ };
+ Local l;
+ l.foo("nmabc");
+ return 0;
+}
+int t = test();
+}
\ No newline at end of file