PR c++/40687
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 3 Nov 2009 17:11:08 +0000 (17:11 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 3 Nov 2009 17:11:08 +0000 (17:11 +0000)
* 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
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/auto3.C

index 10fa16a..6c7bdc6 100644 (file)
@@ -1,3 +1,8 @@
+2009-11-03  Jason Merrill  <jason@redhat.com>
+
+       PR c++/40687
+       * pt.c (do_auto_deduction): Diagnose inconsistent deduction.
+
 2009-11-02  Dodji Seketeli  <dodji@redhat.com>
 
        PR c++/37093
index 5af348a..db2f969 100644 (file)
@@ -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);
index 859b5f1..ab594d7 100644 (file)
@@ -1,3 +1,8 @@
+2009-11-03  Jason Merrill  <jason@redhat.com>
+
+       PR c++/40687
+       * g++.dg/cpp0x/auto3.C: Remove xfail.
+
 2009-11-03  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/41907
index 3cea856..f792c07 100644 (file)
@@ -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" }