From bcb47f721233dc9414cbcda0fd20e3ab6ddd2f46 Mon Sep 17 00:00:00 2001 From: jason Date: Tue, 3 Nov 2009 17:11:08 +0000 Subject: [PATCH] PR c++/40687 * pt.c (do_auto_deduction): Diagnose inconsistent deduction. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@153855 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/pt.c | 18 ++++++++++++++---- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp0x/auto3.C | 2 +- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 10fa16a..6c7bdc6 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2009-11-03 Jason Merrill + + PR c++/40687 + * pt.c (do_auto_deduction): Diagnose inconsistent deduction. + 2009-11-02 Dodji Seketeli PR c++/37093 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 5af348a..db2f969 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -17796,10 +17796,7 @@ make_args_non_dependent (VEC(tree,gc) *args) tree make_auto (void) { - tree au; - - /* ??? Is it worth caching this for multiple autos at the same level? */ - au = cxx_make_type (TEMPLATE_TYPE_PARM); + tree au = cxx_make_type (TEMPLATE_TYPE_PARM); TYPE_NAME (au) = build_decl (BUILTINS_LOCATION, TYPE_DECL, get_identifier ("auto"), au); TYPE_STUB_DECL (au) = TYPE_NAME (au); @@ -17877,6 +17874,19 @@ do_auto_deduction (tree type, tree init, tree auto_node) return error_mark_node; } + /* If the list of declarators contains more than one declarator, the type + of each declared variable is determined as described above. If the + type deduced for the template parameter U is not the same in each + deduction, the program is ill-formed. */ + if (TREE_TYPE (auto_node) + && !same_type_p (TREE_TYPE (auto_node), TREE_VEC_ELT (targs, 0))) + { + error ("inconsistent deduction for %qT: %qT and then %qT", + auto_node, TREE_TYPE (auto_node), TREE_VEC_ELT (targs, 0)); + return error_mark_node; + } + TREE_TYPE (auto_node) = TREE_VEC_ELT (targs, 0); + if (processing_template_decl) targs = add_to_template_args (current_template_args (), targs); return tsubst (type, targs, tf_warning_or_error, NULL_TREE); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 859b5f1..ab594d7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2009-11-03 Jason Merrill + + PR c++/40687 + * g++.dg/cpp0x/auto3.C: Remove xfail. + 2009-11-03 Tobias Burnus PR fortran/41907 diff --git a/gcc/testsuite/g++.dg/cpp0x/auto3.C b/gcc/testsuite/g++.dg/cpp0x/auto3.C index 3cea856..f792c07 100644 --- a/gcc/testsuite/g++.dg/cpp0x/auto3.C +++ b/gcc/testsuite/g++.dg/cpp0x/auto3.C @@ -7,7 +7,7 @@ auto x; // { dg-error "auto" } // If the type deduced for the template parameter U is not the same in each // deduction, the program is ill-formed. -auto i = 42, j = 42.0; // { dg-error "" "" { xfail *-*-* } } +auto i = 42, j = 42.0; // { dg-error "auto" } // New CWG issue auto a[2] = { 1, 2 }; // { dg-error "auto" } -- 2.7.4