Commit 303a1e75 by Jason Merrill Committed by Jason Merrill

PR c++/71569 - ICE with redundant args on member variable template.

	* decl.c (start_decl): Handle partial specialization of member
	variable template.
	* pt.c (determine_specialization): Allow partial specialization
	of member variable template without specializing enclosing class.
	(process_partial_specialization): Improve error message.

Co-Authored-By: Alexandre Oliva <aoliva@redhat.com>

From-SVN: r258102
parent 99daa7a9
2018-03-01 Jason Merrill <jason@redhat.com>
Alexandre Oliva <aoliva@redhat.com>
PR c++/71569 - ICE with redundant args on member variable template.
* decl.c (start_decl): Handle partial specialization of member
variable template.
* pt.c (determine_specialization): Allow partial specialization
of member variable template without specializing enclosing class.
(process_partial_specialization): Improve error message.
2018-02-28 Jason Merrill <jason@redhat.com> 2018-02-28 Jason Merrill <jason@redhat.com>
PR c++/71784 - ICE with ref-qualifier and explicit specialization. PR c++/71784 - ICE with ref-qualifier and explicit specialization.
......
...@@ -5080,19 +5080,17 @@ start_decl (const cp_declarator *declarator, ...@@ -5080,19 +5080,17 @@ start_decl (const cp_declarator *declarator,
if (field == NULL_TREE if (field == NULL_TREE
|| !(VAR_P (field) || variable_template_p (field))) || !(VAR_P (field) || variable_template_p (field)))
error ("%q+#D is not a static data member of %q#T", decl, context); error ("%q+#D is not a static data member of %q#T", decl, context);
else if (variable_template_p (field)
&& (DECL_LANG_SPECIFIC (decl)
&& DECL_TEMPLATE_SPECIALIZATION (decl)))
/* OK, specialization was already checked. */;
else if (variable_template_p (field) && !this_tmpl) else if (variable_template_p (field) && !this_tmpl)
{ {
if (DECL_LANG_SPECIFIC (decl) error_at (DECL_SOURCE_LOCATION (decl),
&& DECL_TEMPLATE_SPECIALIZATION (decl)) "non-member-template declaration of %qD", decl);
/* OK, specialization was already checked. */; inform (DECL_SOURCE_LOCATION (field), "does not match "
else "member template declaration here");
{ return error_mark_node;
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 else
{ {
......
...@@ -2060,7 +2060,8 @@ determine_specialization (tree template_id, ...@@ -2060,7 +2060,8 @@ determine_specialization (tree template_id,
/* We shouldn't be specializing a member template of an /* We shouldn't be specializing a member template of an
unspecialized class template; we already gave an error in unspecialized class template; we already gave an error in
check_specialization_scope, now avoid crashing. */ check_specialization_scope, now avoid crashing. */
if (template_count && DECL_CLASS_SCOPE_P (decl) if (!VAR_P (decl)
&& template_count && DECL_CLASS_SCOPE_P (decl)
&& template_class_depth (DECL_CONTEXT (decl)) > 0) && template_class_depth (DECL_CONTEXT (decl)) > 0)
{ {
gcc_assert (errorcount); gcc_assert (errorcount);
...@@ -4840,10 +4841,13 @@ process_partial_specialization (tree decl) ...@@ -4840,10 +4841,13 @@ process_partial_specialization (tree decl)
{ {
if (!flag_concepts) if (!flag_concepts)
error ("partial specialization %q+D does not specialize " error ("partial specialization %q+D does not specialize "
"any template arguments", decl); "any template arguments; to define the primary template, "
"remove the template argument list", decl);
else else
error ("partial specialization %q+D does not specialize any " error ("partial specialization %q+D does not specialize any "
"template arguments and is not more constrained than", decl); "template arguments and is not more constrained than "
"the primary template; to define the primary template, "
"remove the template argument list", decl);
inform (DECL_SOURCE_LOCATION (maintmpl), "primary template here"); inform (DECL_SOURCE_LOCATION (maintmpl), "primary template here");
} }
......
// PR c++/71569
// { dg-do compile { target c++14 } }
template <class T>
struct A {
template <class U>
static const U u;
};
template <class T>
template <class U>
const U A<T>::u<U> = 0; // { dg-error "does not specialize" }
// PR c++/71569
// { dg-do compile { target c++14 } }
template <class T>
struct A {
template <class U>
static const U u;
};
template <class T>
template <class U>
const U* A<T>::u<U*> = 0;
const int *p = A<char>::u<int*>;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment