diff options
author | Nathan Sidwell <nathan@codesourcery.com> | 2005-10-17 11:19:12 +0000 |
---|---|---|
committer | Nathan Sidwell <nathan@gcc.gnu.org> | 2005-10-17 11:19:12 +0000 |
commit | c3ee4651b244be21eaa251676afc4f052727a0b5 (patch) | |
tree | 7d8824489867a310bab522176b3c8b9255de8127 /gcc | |
parent | 5acaf46030143cbb7e08c5c1dde13adff84d8e10 (diff) | |
download | gcc-c3ee4651b244be21eaa251676afc4f052727a0b5.zip gcc-c3ee4651b244be21eaa251676afc4f052727a0b5.tar.gz gcc-c3ee4651b244be21eaa251676afc4f052727a0b5.tar.bz2 |
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
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 10 | ||||
-rw-r--r-- | gcc/cp/decl.c | 13 | ||||
-rw-r--r-- | gcc/cp/parser.c | 3 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/template/defarg6.C | 25 |
5 files changed, 46 insertions, 10 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 9305e16..a725969 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -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 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index eafebc1..982fe12 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 7f27943..45fc69f 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 701122a..6eeadc5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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 diff --git a/gcc/testsuite/g++.dg/template/defarg6.C b/gcc/testsuite/g++.dg/template/defarg6.C new file mode 100644 index 0000000..f4d8468 --- /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 <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" "" } +} |