From: Paolo Carlini Date: Mon, 5 Oct 2015 21:43:26 +0000 (+0000) Subject: re PR c++/53856 (Default argument allowed on member defined outside of class template) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=fcbc0f7cf76a9ee075003fe38ae900bf4842becc;p=gcc.git re PR c++/53856 (Default argument allowed on member defined outside of class template) /cp 2015-10-05 Paolo Carlini 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 PR c++/53856 * g++.dg/template/defarg19.C: New. * g++.dg/template/defarg20.C: Likewise. From-SVN: r228501 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index d4fd5146eed..63ed0473f2d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2015-10-05 Paolo Carlini + + 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 * tree.c (cp_tree_equal): Use real_equal instead of diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index db947cc632e..6520b8b31e5 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index cbec9c9fb12..3d268e7206c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2015-10-05 Paolo Carlini + + PR c++/53856 + * g++.dg/template/defarg19.C: New. + * g++.dg/template/defarg20.C: Likewise. + 2015-10-05 Aditya Kumar Sebastian Pop diff --git a/gcc/testsuite/g++.dg/template/defarg19.C b/gcc/testsuite/g++.dg/template/defarg19.C new file mode 100644 index 00000000000..856980232f4 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/defarg19.C @@ -0,0 +1,15 @@ +// PR c++/53856 + +template +struct A +{ + struct B; +}; + +template +struct A::B // { dg-error "default argument" } +{ + int i; +}; + +A::B b = { }; diff --git a/gcc/testsuite/g++.dg/template/defarg20.C b/gcc/testsuite/g++.dg/template/defarg20.C new file mode 100644 index 00000000000..de8aac11ec2 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/defarg20.C @@ -0,0 +1,15 @@ +// PR c++/53856 + +struct A +{ + template + struct B; +}; + +template +struct A::B +{ + int i; +}; + +A::B b = { };