diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 576cbd1..ff2217e 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -10062,9 +10062,12 @@ void Sema::ActOnFields(Scope* S,
 
   // If there's a #pragma GCC visibility in scope, and this isn't a subclass,
   // set the visibility of this record.
-  if (Record && !Record->getDeclContext()->isRecord() &&
-      !isa<ClassTemplateSpecializationDecl>(Record))
-    AddPushedVisibilityAttribute(Record);
+  if (Record && !Record->getDeclContext()->isRecord()) {
+    ClassTemplateSpecializationDecl *Specialization =
+      dyn_cast<ClassTemplateSpecializationDecl>(Record);
+    if (!Specialization || Specialization->isExplicitSpecialization())
+      AddPushedVisibilityAttribute(Record);
+  }
 }
 
 /// \brief Determine whether the given integral value is representable within
diff --git a/test/CodeGenCXX/visibility.cpp b/test/CodeGenCXX/visibility.cpp
index 60a7792..a6425cb 100644
--- a/test/CodeGenCXX/visibility.cpp
+++ b/test/CodeGenCXX/visibility.cpp
@@ -980,10 +980,17 @@ namespace test53 {
     static void       _M_fill_insert();
   };
 #pragma GCC visibility push(hidden)
+  template<>
+  struct vector<int> {
+    static void       _M_fill_insert();
+  };
   void foo() {
     vector<unsigned>::_M_fill_insert();
+    vector<int>::_M_fill_insert();
   }
 #pragma GCC visibility pop
   // CHECK: declare void @_ZN6test536vectorIjE14_M_fill_insertEv
   // CHECK-HIDDEN: declare void @_ZN6test536vectorIjE14_M_fill_insertEv
+  // CHECK: declare hidden void @_ZN6test536vectorIiE14_M_fill_insertEv
+  // CHECK-HIDDEN: declare hidden void @_ZN6test536vectorIiE14_M_fill_insertEv
 }
