From: Jason Merrill Date: Fri, 12 Sep 2014 14:39:25 +0000 (-0400) Subject: re PR c++/63201 (Full specialization of a member variable template of a class templat... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4ee28eb7cea6ebf4713ad1f808d7e5e033ff508a;p=gcc.git re PR c++/63201 (Full specialization of a member variable template of a class template does not work) PR c++/63201 * decl.c (start_decl): Handle specialization of member variable template. * pt.c (check_explicit_specialization): Adjust error. From-SVN: r215226 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index afefed4e623..3e9cb896824 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2014-09-11 Jason Merrill + + PR c++/63201 + * decl.c (start_decl): Handle specialization of member variable + template. + * pt.c (check_explicit_specialization): Adjust error. + 2014-09-11 Paolo Carlini PR c++/61489 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 6e195bb803d..59dada7d3db 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -4659,20 +4659,24 @@ start_decl (const cp_declarator *declarator, if (field == NULL_TREE || !(VAR_P (field) || variable_template_p (field))) error ("%q+#D is not a static data member of %q#T", decl, context); - else + else if (variable_template_p (field) && !this_tmpl) { - if (variable_template_p (field)) + if (DECL_LANG_SPECIFIC (decl) + && DECL_TEMPLATE_SPECIALIZATION (decl)) + /* OK, specialization was already checked. */; + else { - if (!this_tmpl) - { - error_at (DECL_SOURCE_LOCATION (decl), - "non-member-template declaration of %qD", decl); - inform (DECL_SOURCE_LOCATION (field), "does not match " - "member template declaration here"); - return error_mark_node; - } - field = DECL_TEMPLATE_RESULT (field); + error_at (DECL_SOURCE_LOCATION (decl), + "non-member-template declaration of %qD", decl); + inform (DECL_SOURCE_LOCATION (field), "does not match " + "member template declaration here"); + return error_mark_node; } + } + else + { + if (variable_template_p (field)) + field = DECL_TEMPLATE_RESULT (field); if (DECL_CONTEXT (field) != context) { diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 7f7ab930890..008879b28d5 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -2471,7 +2471,7 @@ check_explicit_specialization (tree declarator, template void f(); */ if (uses_template_parms (declarator)) - error ("function template partial specialization %qD " + error ("non-type partial specialization %qD " "is not allowed", declarator); else error ("template-id %qD in declaration of primary template", diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ11.C b/gcc/testsuite/g++.dg/cpp1y/var-templ11.C new file mode 100644 index 00000000000..5d6e0d0dcff --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/var-templ11.C @@ -0,0 +1,67 @@ +// PR c++/63201 +// { dg-do compile { target c++14 } } + +template +struct Y +{ + template static U x; +}; + +template +template +U Y::x = U(); + +template <> +template +U Y::x = 42; + +template <> +template +// odd diagnostic +U Y::x = 42; // { dg-error "partial specialization" } + +template <> +template <> +int Y::x = 42; // { dg-bogus "non-member-template declaration" } + +template +struct Z +{ + template struct ZZ + { + template static V x; + }; +}; + +template +template +template +V Z::ZZ::x = V(); + +template <> +template <> +template +V Z::ZZ::x = V(); + +template <> +template +struct Z::ZZ +{ + template static V x; +}; + +template <> +template +template +V Z::ZZ::x = V(); + +template <> +template <> +template <> +int Z::ZZ::x = 42; // { dg-bogus "non-member-template declaration" } + +int main() +{ + int y = Y::x; + int z = Z::ZZ::x; +} diff --git a/gcc/testsuite/g++.old-deja/g++.robertl/eb103.C b/gcc/testsuite/g++.old-deja/g++.robertl/eb103.C index c272d940332..ffc51ee4411 100644 --- a/gcc/testsuite/g++.old-deja/g++.robertl/eb103.C +++ b/gcc/testsuite/g++.old-deja/g++.robertl/eb103.C @@ -4,7 +4,7 @@ template inline unsigned f (unsigned* ptr); template -inline unsigned f (unsigned* ptr) // { dg-error "function template partial specialization" } +inline unsigned f (unsigned* ptr) // { dg-error "partial specialization" } { return 1; }