PR c++/43281
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 22 Mar 2010 20:38:46 +0000 (20:38 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 22 Mar 2010 20:38:46 +0000 (20:38 +0000)
* 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

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/auto18.C [new file with mode: 0644]

index 5474df9..fd08a54 100644 (file)
@@ -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:
index 66e7d73..f5d68f8 100644 (file)
@@ -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
index 25cc5b9..99f6747 100644 (file)
@@ -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 (file)
index 0000000..17f7f99
--- /dev/null
@@ -0,0 +1,6 @@
+// { dg-options "-std=c++0x" }
+
+void f()
+{
+  auto val = val;  // { dg-error "auto. type used in its own initializer" }
+}