Patchwork C++ PATCH for explicit+auto

login
register
mail settings
Submitter Jason Merrill
Date Sept. 6, 2010, 4:43 a.m.
Message ID <4C847168.5020600@redhat.com>
Download mbox | patch
Permalink /patch/63873/
State New
Headers show

Comments

Jason Merrill - Sept. 6, 2010, 4:43 a.m.
In this testcase, we were stripping the TREE_LIST from the initializer 
in order to do auto deduction, which meant forgetting that we were doing 
direct-initialization.

Tested x86_64-pc-linux-gnu, applied to trunk.

Patch

commit 1190946b97d3fe4845c320d46817547404b8bff3
Author: Jason Merrill <jason@redhat.com>
Date:   Sun Sep 5 22:40:51 2010 -0400

    	* decl.c (cp_finish_decl): Don't change init for auto deduction.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 75fd9f7..409836c 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -5681,18 +5681,21 @@  cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
   auto_node = type_uses_auto (type);
   if (auto_node)
     {
+      tree d_init;
       if (init == NULL_TREE)
 	{
 	  error ("declaration of %q#D has no initializer", decl);
 	  TREE_TYPE (decl) = error_mark_node;
 	  return;
 	}
-      if (TREE_CODE (init) == TREE_LIST)
-	init = build_x_compound_expr_from_list (init, ELK_INIT,
-						tf_warning_or_error);
-      if (describable_type (init))
+      d_init = init;
+      if (TREE_CODE (d_init) == TREE_LIST)
+	d_init = build_x_compound_expr_from_list (d_init, ELK_INIT,
+						  tf_warning_or_error);
+      if (describable_type (d_init))
 	{
-	  type = TREE_TYPE (decl) = do_auto_deduction (type, init, auto_node);
+	  type = TREE_TYPE (decl) = do_auto_deduction (type, d_init,
+						       auto_node);
 	  if (type == error_mark_node)
 	    return;
 	}
diff --git a/gcc/testsuite/g++.dg/cpp0x/auto19.C b/gcc/testsuite/g++.dg/cpp0x/auto19.C
new file mode 100644
index 0000000..f709902
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/auto19.C
@@ -0,0 +1,8 @@ 
+// { dg-options -std=c++0x }
+
+struct Explicit {
+  Explicit() = default;  // Line 2
+  explicit Explicit(const Explicit&){}
+} ex;
+
+auto ex2(ex); // Line 6