re PR c++/53856 (Default argument allowed on member defined outside of class template)

/cp
2015-10-05  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/53856
	* pt.c (check_default_tmpl_args): Per [temp.param]/9, do not
	reject default template arguments in out of class definitions
	of members of non-template classes.

/testsuite
2015-10-05  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/53856
	* g++.dg/template/defarg19.C: New.
	* g++.dg/template/defarg20.C: Likewise.

From-SVN: r228501
This commit is contained in:
Paolo Carlini 2015-10-05 21:43:26 +00:00 committed by Paolo Carlini
parent 1970d84915
commit fcbc0f7cf7
5 changed files with 51 additions and 1 deletions

View File

@ -1,3 +1,10 @@
2015-10-05 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/53856
* pt.c (check_default_tmpl_args): Per [temp.param]/9, do not
reject default template arguments in out of class definitions
of members of non-template classes.
2015-10-05 Richard Sandiford <richard.sandiford@arm.com>
* tree.c (cp_tree_equal): Use real_equal instead of

View File

@ -4940,8 +4940,15 @@ check_default_tmpl_args (tree decl, tree parms, bool is_primary,
else if (is_partial)
msg = G_("default template arguments may not be used in "
"partial specializations");
else
else if (current_class_type && CLASSTYPE_IS_TEMPLATE (current_class_type))
msg = G_("default argument for template parameter for class enclosing %qD");
else
/* Per [temp.param]/9, "A default template-argument shall not be
specified in the template-parameter-lists of the definition of
a member of a class template that appears outside of the member's
class.", thus if we aren't handling a member of a class template
there is no need to examine the parameters. */
return true;
if (current_class_type && TYPE_BEING_DEFINED (current_class_type))
/* If we're inside a class definition, there's no need to

View File

@ -1,3 +1,9 @@
2015-10-05 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/53856
* g++.dg/template/defarg19.C: New.
* g++.dg/template/defarg20.C: Likewise.
2015-10-05 Aditya Kumar <aditya.k7@samsung.com>
Sebastian Pop <s.pop@samsung.com>

View File

@ -0,0 +1,15 @@
// PR c++/53856
template<typename T>
struct A
{
struct B;
};
template<typename T = int>
struct A<T>::B // { dg-error "default argument" }
{
int i;
};
A<int>::B b = { };

View File

@ -0,0 +1,15 @@
// PR c++/53856
struct A
{
template<typename T>
struct B;
};
template<typename T = int>
struct A::B
{
int i;
};
A::B<int> b = { };