]> granicus.if.org Git - clang/commitdiff
Only instantiate members of nested classes in local classes once, rather than once...
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 4 Jan 2017 23:45:01 +0000 (23:45 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 4 Jan 2017 23:45:01 +0000 (23:45 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@291034 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplateInstantiateDecl.cpp
test/SemaTemplate/instantiate-local-class.cpp

index 7328dcb8760fad168d8c868ee83fc46a9e5407d1..3cc938106d80273ae04d8742ad8a9c3fde5974c2 100644 (file)
@@ -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.
index a61af7a5af38a6f2d7a2f2f5ba3b08e29875768c..eaff4c4bbc8d9011c99d49a636aba2568df16ed6 100644 (file)
@@ -475,3 +475,14 @@ namespace rdar23721638 {
   }
   template void bar<A>(); // expected-note {{in instantiation}}
 }
+
+namespace anon_union_default_member_init {
+  template<typename T> void f() {
+    struct S {
+      union {
+        int i = 0;
+      };
+    };
+  }
+  void g() { f<int>(); }
+}