diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index b4a4eb1..e2f858d 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -442,9 +442,11 @@ static LinkageInfo getLVForNamespaceScopeDecl(const NamedDecl *D, LVFlags F) {
         LV.merge(getLVForDecl(spec->getSpecializedTemplate(),
                               F.onlyTemplateVisibility()));
 
-        // The arguments at which the template was instantiated.
-        const TemplateArgumentList &TemplateArgs = spec->getTemplateArgs();
-        LV.merge(getLVForTemplateArgumentList(TemplateArgs, F));
+        if (!LV.visibilityExplicit()) {
+          // the arguments at which the template was instantiated.
+          const TemplateArgumentList &TemplateArgs = spec->getTemplateArgs();
+          LV.merge(getLVForTemplateArgumentList(TemplateArgs, F));
+        }
       }
     }
 
diff --git a/test/CodeGenCXX/visibility.cpp b/test/CodeGenCXX/visibility.cpp
index ce1e8fd..50d2fdf 100644
--- a/test/CodeGenCXX/visibility.cpp
+++ b/test/CodeGenCXX/visibility.cpp
@@ -456,7 +456,7 @@ namespace test22 {
 }
 
 namespace PR10113 {
-  namespace foo __attribute__ ((__visibility__ ("default"))) {
+  namespace foo DEFAULT {
     template<typename T>
       class bar {
       void zed() {}
@@ -465,4 +465,10 @@ namespace PR10113 {
   template class foo::bar<char>;
   // CHECK: define weak_odr void @_ZN7PR101133foo3barIcE3zedEv
   // CHECK-HIDDEN: define weak_odr void @_ZN7PR101133foo3barIcE3zedEv
+
+  struct zed {
+  };
+  template class foo::bar<zed>;
+  // CHECK: define weak_odr void @_ZN7PR101133foo3barINS_3zedEE3zedEv
+  // CHECK-HIDDEN: define weak_odr void @_ZN7PR101133foo3barINS_3zedEE3zedEv
 }
