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
This commit is contained in:
Nathan Sidwell 2005-10-17 11:19:12 +00:00 committed by Nathan Sidwell
parent 5acaf46030
commit c3ee4651b2
5 changed files with 46 additions and 10 deletions

View File

@ -1,3 +1,13 @@
2005-10-17 Nathan Sidwell <nathan@codesourcery.com>
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 <mark@codesourcery.com>
PR c++/24389

View File

@ -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;

View File

@ -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. */

View File

@ -1,3 +1,8 @@
2005-10-17 Nathan Sidwell <nathan@codesourcery.com>
PR c++/21353
* g++.dg/template/defarg6.C: New.
2005-10-17 Uros Bizjak <uros@kss-loka.si>
PR target/24315

View File

@ -0,0 +1,25 @@
// Copyright (C) 2005 Free Software Foundation, Inc.
// Contributed by Nathan Sidwell 14 Oct 2005 <nathan@codesourcery.com>
// PR 21353 missing error.
// Origin:Andrew Pinski <pinskia@gcc.gnu.org>
enum X{ a, b, c };
struct C
{
static void func (X &ref = a); // { dg-error "default argument" "" }
};
template <typename T>
struct D
{
static void func (X &ref = a); // not an error at this point
};
void Foo (X & obj)
{
D<int>::func (obj);
D<int>::func (); // { dg-error "default argument" "" }
}