<p dir="ltr">Test case? Also I think we're trying to avoid implementing every random extension from msvc, preferring to update choose where the number of instances of code relying on the extension is small (& not in a platform header) - do you have a particular case where this shows up a lot (such that it's a substaintial burden to update the code to be conforming)? </p>
<p dir="ltr">I might be wrong about this, so others may come in to correct me, that's just my vague understanding</p>
<div class="gmail_quote">On Mar 12, 2015 2:07 AM, "Alexey Frolov" <<a href="mailto:alexfrolov1878@yandex.ru">alexfrolov1878@yandex.ru</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi rsmith,<br>
<br>
MS compiler emits no errors in case of explicit specializations outside declaration enclosing namespaces, even when language extensions are disabled.<br>
The patch is to suppress errors and emit extension warnings if explicit specializations are not declared in the corresponding namespaces.<br>
<br>
This fixes PR13738.<br>
<br>
REPOSITORY<br>
  rL LLVM<br>
<br>
<a href="http://reviews.llvm.org/D8283" target="_blank">http://reviews.llvm.org/D8283</a><br>
<br>
Files:<br>
  llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td<br>
  llvm/tools/clang/lib/Sema/SemaTemplate.cpp<br>
  llvm/tools/clang/test/SemaTemplate/ext_ms_template_spec.cpp<br>
<br>
Index: llvm/tools/clang/test/SemaTemplate/ext_ms_template_spec.cpp<br>
===================================================================<br>
--- llvm/tools/clang/test/SemaTemplate/ext_ms_template_spec.cpp<br>
+++ llvm/tools/clang/test/SemaTemplate/ext_ms_template_spec.cpp<br>
@@ -0,0 +1,33 @@<br>
+// RUN: %clang_cc1 -fsyntax-only -fms-compatibility -std=c++11 -verify %s<br>
+<br>
+namespace A {<br>
+<br>
+template <class T><br>
+class ClassTemplate; // expected-note {{explicitly specialized declaration is here}}<br>
+<br>
+template <class T1, class T2><br>
+class ClassTemplatePartial; // expected-note {{explicitly specialized declaration is here}}<br>
+<br>
+template <typename T> struct X {<br>
+  struct MemberClass; // expected-note {{explicitly specialized declaration is here}}<br>
+  enum MemberEnumeration; // expected-note {{explicitly specialized declaration is here}}<br>
+};<br>
+<br>
+}<br>
+<br>
+namespace B {<br>
+<br>
+template <><br>
+class A::ClassTemplate<int>; // expected-warning {{class template specialization of 'ClassTemplate' outside namespace enclosing 'A' is a Microsoft extension}}<br>
+<br>
+template <class T1><br>
+class A::ClassTemplatePartial<T1, T1 *> {}; // expected-warning {{class template partial specialization of 'ClassTemplatePartial' outside namespace enclosing 'A' is a Microsoft extension}}<br>
+<br>
+template <><br>
+struct A::X<int>::MemberClass; // expected-warning {{member class specialization of 'MemberClass' outside namespace enclosing 'A' is a Microsoft extension}}<br>
+<br>
+template <><br>
+enum A::X<int>::MemberEnumeration; // expected-warning {{member enumeration specialization of 'MemberEnumeration' outside namespace enclosing 'A' is a Microsoft extension}}<br>
+<br>
+}<br>
+<br>
Index: llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td<br>
===================================================================<br>
--- llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td<br>
+++ llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td<br>
@@ -3445,6 +3445,12 @@<br>
   "variable template partial|function template|member "<br>
   "function|static data member|member class|member enumeration}0 "<br>
   "specialization of %1 not in a namespace enclosing %2">;<br>
+def ext_ms_template_spec_redecl_out_of_scope: ExtWarn<<br>
+  "%select{class template|class template partial|variable template|"<br>
+  "variable template partial|function template|member "<br>
+  "function|static data member|member class|member enumeration}0 "<br>
+  "specialization of %1 outside namespace enclosing %2 "<br>
+  "is a Microsoft extension">, InGroup<Microsoft>;<br>
 def err_template_spec_redecl_global_scope : Error<<br>
   "%select{class template|class template partial|variable template|"<br>
   "variable template partial|function template|member "<br>
Index: llvm/tools/clang/lib/Sema/SemaTemplate.cpp<br>
===================================================================<br>
--- llvm/tools/clang/lib/Sema/SemaTemplate.cpp<br>
+++ llvm/tools/clang/lib/Sema/SemaTemplate.cpp<br>
@@ -5835,11 +5835,13 @@<br>
     if (isa<TranslationUnitDecl>(SpecializedContext))<br>
       S.Diag(Loc, diag::err_template_spec_redecl_global_scope)<br>
         << EntityKind << Specialized;<br>
-    else if (isa<NamespaceDecl>(SpecializedContext))<br>
-      S.Diag(Loc, diag::err_template_spec_redecl_out_of_scope)<br>
-        << EntityKind << Specialized<br>
-        << cast<NamedDecl>(SpecializedContext);<br>
-    else<br>
+    else if (isa<NamespaceDecl>(SpecializedContext)) {<br>
+      int Diag = diag::err_template_spec_redecl_out_of_scope;<br>
+      if (S.getLangOpts().MSVCCompat)<br>
+        Diag = diag::ext_ms_template_spec_redecl_out_of_scope;<br>
+      S.Diag(Loc, Diag) << EntityKind << Specialized<br>
+                        << cast<NamedDecl>(SpecializedContext);<br>
+    } else<br>
       llvm_unreachable("unexpected namespace context for specialization");<br>
<br>
     S.Diag(Specialized->getLocation(), diag::note_specialized_entity);<br>
<br>
EMAIL PREFERENCES<br>
  <a href="http://reviews.llvm.org/settings/panel/emailpreferences/" target="_blank">http://reviews.llvm.org/settings/panel/emailpreferences/</a><br>
<br>_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div>