Bug 63705 - function template specialization outside namespace rejected with C++11
Summary: function template specialization outside namespace rejected with C++11
Status: RESOLVED DUPLICATE of bug 56480
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 5.0
: P3 normal
Target Milestone: 5.0
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2014-11-01 09:08 UTC by Markus Trippelsdorf
Modified: 2014-11-01 15:51 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-11-01 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Trippelsdorf 2014-11-01 09:08:49 UTC
Please consider:

markus@x4 ~ % cat te.ii
namespace N
{
template <typename T1>
void
f (const T1) {}
}

template <>
void
N::f (const int) {}

markus@x4 ~ % clang++ -std=c++11 -c te.ii
markus@x4 ~ % icpc -std=c++11 -c te.ii
markus@x4 ~ % g++ -std=c++11 -c te.ii
te.ii:10:16: error: specialization of ‘template<class T1> void N::f(T1)’ in different namespace [-fpermissive]
 N::f (const int) {}
                ^
te.ii:5:1: error:   from definition of ‘template<class T1> void N::f(T1)’ [-fpermissive]
 f (const T1) {}
 ^

markus@x4 ~ % clang++ -c te.ii
te.ii:10:4: warning: first declaration of function template specialization of 'f' outside namespace 'N' is a C++11 extension [-Wc++11-extensions]
N::f (const int) {}
   ^
te.ii:5:1: note: explicitly specialized declaration is here
f (const T1) {}
Comment 1 Markus Trippelsdorf 2014-11-01 09:15:46 UTC
Not a regression.
Comment 3 Markus Trippelsdorf 2014-11-01 13:27:49 UTC
Possible (untested) fix:

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 2cf10f4..1171b5d 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -780,15 +780,15 @@ check_specialization_namespace (tree tmpl)
       error ("specialization of %qD must appear at namespace scope", tmpl);
       return false;
     }
-  if (is_associated_namespace (current_namespace, tpl_ns))
-    /* Same or super-using namespace.  */
-    return true;
-  else
+  if (!is_associated_namespace (current_namespace, tpl_ns) &&
+      (cxx_dialect < cxx11))
     {
       permerror (input_location, "specialization of %qD in different namespace", tmpl);
       permerror (input_location, "  from definition of %q+#D", tmpl);
       return false;
     }
+
+  return true;
 }
 
 /* SPEC is an explicit instantiation.  Check that it is valid to
Comment 4 Jonathan Wakely 2014-11-01 15:49:35 UTC
PR 56480 ?
Comment 5 Markus Trippelsdorf 2014-11-01 15:51:27 UTC
(In reply to Jonathan Wakely from comment #4)
> PR 56480 ?

Yes. Thanks.

*** This bug has been marked as a duplicate of bug 56480 ***