diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index e4a8ef59b435..5520f6404478 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -1447,7 +1447,7 @@ Sema::InstantiateClassMembers(SourceLocation PointOfInstantiation, if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK, Function, MSInfo->getTemplateSpecializationKind(), - MSInfo->getPointOfInstantiation(), + MSInfo->getPointOfInstantiation(), SuppressNew) || SuppressNew) continue; @@ -1483,7 +1483,7 @@ Sema::InstantiateClassMembers(SourceLocation PointOfInstantiation, if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK, Var, MSInfo->getTemplateSpecializationKind(), - MSInfo->getPointOfInstantiation(), + MSInfo->getPointOfInstantiation(), SuppressNew) || SuppressNew) continue; @@ -1518,11 +1518,11 @@ Sema::InstantiateClassMembers(SourceLocation PointOfInstantiation, if (MSInfo->getTemplateSpecializationKind() == TSK_ExplicitSpecialization) continue; - + if (CheckSpecializationInstantiationRedecl(PointOfInstantiation, TSK, Record, MSInfo->getTemplateSpecializationKind(), - MSInfo->getPointOfInstantiation(), + MSInfo->getPointOfInstantiation(), SuppressNew) || SuppressNew) continue; @@ -1549,6 +1549,13 @@ Sema::InstantiateClassMembers(SourceLocation PointOfInstantiation, InstantiateClass(PointOfInstantiation, Record, Pattern, TemplateArgs, TSK); + } else { + if (TSK == TSK_ExplicitInstantiationDefinition && + Record->getTemplateSpecializationKind() == + TSK_ExplicitInstantiationDeclaration) { + Record->setTemplateSpecializationKind(TSK); + MarkVTableUsed(PointOfInstantiation, Record, true); + } } Pattern = cast_or_null(Record->getDefinition()); diff --git a/clang/test/CodeGenCXX/template-inner-struct-visibility-hidden.cpp b/clang/test/CodeGenCXX/template-inner-struct-visibility-hidden.cpp new file mode 100644 index 000000000000..ca4446cd200e --- /dev/null +++ b/clang/test/CodeGenCXX/template-inner-struct-visibility-hidden.cpp @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -fvisibility hidden -emit-llvm -o - %s | FileCheck %s + +// Verify that symbols are hidden. +// CHECK: @_ZN1CIiE5Inner6Inner26StaticE = weak hidden global +// CHECK: define weak_odr hidden void @_ZN1CIiE5Inner1fEv +// CHECK: define weak_odr hidden void @_ZN1CIiE5Inner6Inner21gEv + +template +struct C { + struct Inner { + void f(); + struct Inner2 { + void g(); + static int Static; + }; + }; +}; + +template void C::Inner::f() { } +template void C::Inner::Inner2::g() { } +template int C::Inner::Inner2::Static; + +extern template struct C; +template struct C;