This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ PATCH for c++/40306, 40307


Two issues here: in 40307, we were failing to deduce from an initializer specified with (). In 40306, describable_type told us that we could go ahead and deduce the type inside the template, but build_x_indirect_ref hadn't actually given it a type.

Tested x86_64-pc-linux-gnu, applied to trunk.
2009-06-02  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.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index a626a71..645ac7e 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -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)
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index eb28a3d..6f6bd39 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -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);
diff --git a/gcc/testsuite/g++.dg/cpp0x/auto14.C b/gcc/testsuite/g++.dg/cpp0x/auto14.C
new file mode 100644
index 0000000..cb2c4e0
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/auto14.C
@@ -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;
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]