diff options
author | Jason Merrill <jason@redhat.com> | 2010-03-22 16:38:46 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2010-03-22 16:38:46 -0400 |
commit | 189327376c98168ad9445537dcd04d467b09d143 (patch) | |
tree | ee4ab205725aa66f805cec5416356d4084a65c7d | |
parent | ce30e6fd06d9434c9b99162da448d37963fbcf24 (diff) | |
download | gcc-189327376c98168ad9445537dcd04d467b09d143.zip gcc-189327376c98168ad9445537dcd04d467b09d143.tar.gz gcc-189327376c98168ad9445537dcd04d467b09d143.tar.bz2 |
re PR c++/43281 ([c++0x] ICE with invalid auto)
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.
From-SVN: r157651
-rw-r--r-- | gcc/cp/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/cp/pt.c | 26 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 3 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/auto18.C | 6 |
4 files changed, 42 insertions, 0 deletions
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 <jason@redhat.com> + + 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 <simartin@users.sourceforge.net> 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 %<auto%> 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 <jason@redhat.com> + 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" } +} |