Index: lib/Parse/ParseTemplate.cpp =================================================================== --- lib/Parse/ParseTemplate.cpp +++ lib/Parse/ParseTemplate.cpp @@ -1255,15 +1255,23 @@ new ParseScope(this, Scope::TemplateParamScope)); Actions.ActOnReenterTemplateScope(getCurScope(), MD); ++CurTemplateDepthTracker; - } else if (CXXRecordDecl *MD = dyn_cast_or_null(*II)) { - bool IsClassTemplate = MD->getDescribedClassTemplate() != 0; + } else if (CXXRecordDecl *RD = dyn_cast_or_null(*II)) { + ClassTemplateDecl *CTD = RD->getDescribedClassTemplate(); + + if (!CTD) { + if (CXXRecordDecl *Parent = dyn_cast(RD->getParent())) + CTD = Parent->getDescribedClassTemplate(); + } + + bool IsClassTemplate = CTD != 0; TemplateParamScopeStack.push_back( new ParseScope(this, Scope::TemplateParamScope, - /*ManageScope*/IsClassTemplate)); - Actions.ActOnReenterTemplateScope(getCurScope(), - MD->getDescribedClassTemplate()); - if (IsClassTemplate) + /*EnteredScope*/IsClassTemplate)); + + if (IsClassTemplate) { + Actions.ActOnReenterTemplateScope(getCurScope(), CTD); ++CurTemplateDepthTracker; + } } TemplateParamScopeStack.push_back(new ParseScope(this, Scope::DeclScope)); Actions.PushDeclContext(Actions.getCurScope(), *II); Index: test/Parser/DelayedTemplateParsing.cpp =================================================================== --- test/Parser/DelayedTemplateParsing.cpp +++ test/Parser/DelayedTemplateParsing.cpp @@ -123,3 +123,31 @@ template auto invalidTrailingRetType() -> Bogus {} // expected-error {{unknown type name 'Bogus'}} + +namespace PR19613 { + +struct HeapTypeConfig { + static void from_bitset(); +}; + +template +struct TypeImpl { + struct BitsetType; + + static void Any() { + BitsetType::New(); + } +}; + +template +struct TypeImpl::BitsetType { + static void New() { + Config::from_bitset(); + } +}; + +static void f() { + TypeImpl::Any(); +} + +}