OSDN Git Service

PR c++/40306
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 2 Jun 2009 17:02:27 +0000 (17:02 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 2 Jun 2009 17:02:27 +0000 (17:02 +0000)
PR c++/40307
* decl.c (cp_finish_decl): Handle auto deduction from ().
* typeck.c (build_x_indirect_ref): Handle dereferencing an operand
with dependent type that is known to be a pointer.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@148088 138bc75d-0d04-0410-961f-82ee72b054a4

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

index 33fbcef..448b558 100644 (file)
@@ -1,3 +1,11 @@
+2009-06-01  Jason Merrill  <jason@redhat.com>
+
+       PR c++/40306
+       PR c++/40307
+       * decl.c (cp_finish_decl): Handle auto deduction from ().
+       * typeck.c (build_x_indirect_ref): Handle dereferencing an operand
+       with dependent type that is known to be a pointer.
+
 2009-06-02  Simon Martin  <simartin@users.sourceforge.net>
 
        PR c++/38089
index a626a71..645ac7e 100644 (file)
@@ -5531,7 +5531,9 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
          TREE_TYPE (decl) = error_mark_node;
          return;
        }
-      else if (describable_type (init))
+      if (TREE_CODE (init) == TREE_LIST)
+       init = build_x_compound_expr_from_list (init, "initializer");
+      if (describable_type (init))
        {
          type = TREE_TYPE (decl) = do_auto_deduction (type, init, auto_node);
          if (type == error_mark_node)
index eb28a3d..6f6bd39 100644 (file)
@@ -2449,6 +2449,10 @@ build_x_indirect_ref (tree expr, const char *errorstring,
 
   if (processing_template_decl)
     {
+      /* Retain the type if we know the operand is a pointer so that
+        describable_type doesn't make auto deduction break.  */
+      if (TREE_TYPE (expr) && POINTER_TYPE_P (TREE_TYPE (expr)))
+       return build_min (INDIRECT_REF, TREE_TYPE (TREE_TYPE (expr)), expr);
       if (type_dependent_expression_p (expr))
        return build_min_nt (INDIRECT_REF, expr);
       expr = build_non_dependent_expr (expr);
index 6865ff2..9743b5d 100644 (file)
@@ -1,3 +1,7 @@
+2009-06-02  Jason Merrill  <jason@redhat.com>
+
+       * g++.dg/cpp0x/auto14.C: New.
+
 2009-06-02  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gnat.dg/alignment6.adb: Remove XFAIL.
diff --git a/gcc/testsuite/g++.dg/cpp0x/auto14.C b/gcc/testsuite/g++.dg/cpp0x/auto14.C
new file mode 100644 (file)
index 0000000..cb2c4e0
--- /dev/null
@@ -0,0 +1,29 @@
+// PR c++/40306, c++/40307
+// { dg-options "-std=c++0x" }
+// { dg-do run }
+
+template< typename T >
+struct test {
+   test run() {
+      auto tmp = *this;
+      return tmp;
+   }
+   test run_pass() {
+      test tmp( *this );
+      return tmp;
+   }
+
+   test run_fail() {
+      auto tmp( *this );
+      return tmp;
+   }
+};
+
+int main()
+{
+   test<int> x;
+   x.run();
+   x.run_pass();
+   x.run_fail();
+   return 0;
+}