From c3ee4651b244be21eaa251676afc4f052727a0b5 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Mon, 17 Oct 2005 11:19:12 +0000 Subject: [PATCH] re PR c++/21353 (rvalues should not be allowed to be default values for non const references in class functions.) cp: PR c++/21353 * g++.dg/template/defarg6.C: New. testsuite: PR c++/21353 * decl.c (check_default_argument): Don't check processing_template_decl or uses_template_parms here. (grokparms): Only call check_default_argument when not processing a template decl. * parser.c (cp_parser_late_parsing_default_arg): Call check_default_argument when not processing a template decl. From-SVN: r105492 --- gcc/cp/ChangeLog | 10 ++++++++++ gcc/cp/decl.c | 13 +++---------- gcc/cp/parser.c | 3 +++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/template/defarg6.C | 25 +++++++++++++++++++++++++ 5 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/defarg6.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 9305e162458..a7259695193 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,13 @@ +2005-10-17 Nathan Sidwell + + PR c++/21353 + * decl.c (check_default_argument): Don't check + processing_template_decl or uses_template_parms here. + (grokparms): Only call check_default_argument when not processing + a template decl. + * parser.c (cp_parser_late_parsing_default_arg): Call + check_default_argument when not processing a template decl. + 2005-10-16 Mark Mitchell PR c++/24389 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index eafebc188b3..982fe121805 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -8453,13 +8453,6 @@ check_default_argument (tree decl, tree arg) deal with it after the class is complete. */ return arg; - if (processing_template_decl || uses_template_parms (arg)) - /* We don't do anything checking until instantiation-time. Note - that there may be uninstantiated arguments even for an - instantiated function, since default arguments are not - instantiated until they are needed. */ - return arg; - if (TYPE_P (decl)) { decl_type = decl; @@ -8601,10 +8594,10 @@ grokparms (cp_parameter_declarator *first_parm, tree *parms) decl, ptr ? "pointer" : "reference", t); } - if (!any_error && init) - init = check_default_argument (decl, init); - else + if (any_error) init = NULL_TREE; + else if (init && !processing_template_decl) + init = check_default_argument (decl, init); } TREE_CHAIN (decl) = decls; diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 7f279437196..45fc69f1e38 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -15654,6 +15654,9 @@ cp_parser_late_parsing_default_args (cp_parser *parser, tree fn) /* Parse the assignment-expression. */ parsed_arg = cp_parser_assignment_expression (parser, /*cast_p=*/false); + if (!processing_template_decl) + parsed_arg = check_default_argument (TREE_VALUE (parm), parsed_arg); + TREE_PURPOSE (parm) = parsed_arg; /* Update any instantiations we've already created. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 701122a26fe..6eeadc5b343 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2005-10-17 Nathan Sidwell + + PR c++/21353 + * g++.dg/template/defarg6.C: New. + 2005-10-17 Uros Bizjak PR target/24315 diff --git a/gcc/testsuite/g++.dg/template/defarg6.C b/gcc/testsuite/g++.dg/template/defarg6.C new file mode 100644 index 00000000000..f4d84685abe --- /dev/null +++ b/gcc/testsuite/g++.dg/template/defarg6.C @@ -0,0 +1,25 @@ +// Copyright (C) 2005 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 14 Oct 2005 + +// PR 21353 missing error. +// Origin:Andrew Pinski + +enum X{ a, b, c }; + +struct C +{ + static void func (X &ref = a); // { dg-error "default argument" "" } +}; + +template +struct D +{ + static void func (X &ref = a); // not an error at this point +}; + +void Foo (X & obj) +{ + D::func (obj); + + D::func (); // { dg-error "default argument" "" } +}