From ece4758bf28b5be96ef0123ad79456a13e8518a1 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 4 Jan 2017 23:45:01 +0000 Subject: [PATCH] Only instantiate members of nested classes in local classes once, rather than once per enclosing class. llvm-svn: 291034 --- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 7 +++++-- clang/test/SemaTemplate/instantiate-local-class.cpp | 11 +++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 7328dcb8760f..3cc938106d80 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -1470,8 +1470,11 @@ Decl *TemplateDeclInstantiator::VisitCXXRecordDecl(CXXRecordDecl *D) { TSK_ImplicitInstantiation, /*Complain=*/true); - SemaRef.InstantiateClassMembers(D->getLocation(), Record, TemplateArgs, - TSK_ImplicitInstantiation); + // For nested local classes, we will instantiate the members when we + // reach the end of the outermost (non-nested) local class. + if (!D->isCXXClassMember()) + SemaRef.InstantiateClassMembers(D->getLocation(), Record, TemplateArgs, + TSK_ImplicitInstantiation); // This class may have local implicit instantiations that need to be // performed within this scope. diff --git a/clang/test/SemaTemplate/instantiate-local-class.cpp b/clang/test/SemaTemplate/instantiate-local-class.cpp index a61af7a5af38..eaff4c4bbc8d 100644 --- a/clang/test/SemaTemplate/instantiate-local-class.cpp +++ b/clang/test/SemaTemplate/instantiate-local-class.cpp @@ -475,3 +475,14 @@ namespace rdar23721638 { } template void bar(); // expected-note {{in instantiation}} } + +namespace anon_union_default_member_init { + template void f() { + struct S { + union { + int i = 0; + }; + }; + } + void g() { f(); } +}