From: jason Date: Mon, 22 Mar 2010 20:38:46 +0000 (+0000) Subject: PR c++/43281 X-Git-Tag: upstream/4.9.2~30517 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=55027cb553f54d42106fc3e1671bb6233cfdd90a;p=platform%2Fupstream%2Flinaro-gcc.git PR c++/43281 * pt.c (contains_auto_r): New fn. (do_auto_deduction): Use it. (tsubst): Don't look at TREE_TYPE of a TEMPLATE_TYPE_PARM. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@157651 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 5474df9..fd08a54 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2010-03-22 Jason Merrill + + PR c++/43281 + * pt.c (contains_auto_r): New fn. + (do_auto_deduction): Use it. + (tsubst): Don't look at TREE_TYPE of a TEMPLATE_TYPE_PARM. + 2010-03-20 Simon Martin PR c++/43081: diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 66e7d73..f5d68f8 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -9921,6 +9921,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl) if (type && TREE_CODE (t) != TYPENAME_TYPE + && TREE_CODE (t) != TEMPLATE_TYPE_PARM && TREE_CODE (t) != IDENTIFIER_NODE && TREE_CODE (t) != FUNCTION_TYPE && TREE_CODE (t) != METHOD_TYPE) @@ -18240,6 +18241,20 @@ listify_autos (tree type, tree auto_node) return tsubst (type, argvec, tf_warning_or_error, NULL_TREE); } +/* walk_tree helper for do_auto_deduction. */ + +static tree +contains_auto_r (tree *tp, int *walk_subtrees ATTRIBUTE_UNUSED, + void *type) +{ + /* Is this a variable with the type we're looking for? */ + if (DECL_P (*tp) + && TREE_TYPE (*tp) == type) + return *tp; + else + return NULL_TREE; +} + /* Replace occurrences of 'auto' in TYPE with the appropriate type deduced from INIT. AUTO_NODE is the TEMPLATE_TYPE_PARM used for 'auto' in TYPE. */ @@ -18248,8 +18263,19 @@ do_auto_deduction (tree type, tree init, tree auto_node) { tree parms, tparms, targs; tree args[1]; + tree decl; int val; + /* The name of the object being declared shall not appear in the + initializer expression. */ + decl = cp_walk_tree_without_duplicates (&init, contains_auto_r, type); + if (decl) + { + error ("variable %q#D with % type used in its own " + "initializer", decl); + return error_mark_node; + } + /* [dcl.spec.auto]: Obtain P from T by replacing the occurrences of auto with either a new invented type template parameter U or, if the initializer is a braced-init-list (8.5.4), with diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 25cc5b9..99f6747 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2010-03-22 Jason Merrill + PR c++/43281 + * g++.dg/cpp0x/auto18.C: New. + * gcc.dg/pr36997.c: Adjust error message. * g++.dg/ext/vector9.C: Likewise. * g++.dg/conversion/simd3.C: Likewise. diff --git a/gcc/testsuite/g++.dg/cpp0x/auto18.C b/gcc/testsuite/g++.dg/cpp0x/auto18.C new file mode 100644 index 0000000..17f7f99 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/auto18.C @@ -0,0 +1,6 @@ +// { dg-options "-std=c++0x" } + +void f() +{ + auto val = val; // { dg-error "auto. type used in its own initializer" } +}