* call.c (implicit_conversion): Fix value-init of enums.
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 6 Sep 2010 04:49:33 +0000 (04:49 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 6 Sep 2010 04:49:33 +0000 (04:49 +0000)
(convert_like_real): Likewise.

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

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

index 58bcab4..389842d 100644 (file)
@@ -1,5 +1,8 @@
 2010-09-06  Jason Merrill  <jason@redhat.com>
 
+       * call.c (implicit_conversion): Fix value-init of enums.
+       (convert_like_real): Likewise.
+
        * decl.c (cp_finish_decl): Don't change init for auto deduction.
 
        * pt.c (fold_non_dependent_expr_sfinae): Split out from...
index 36f5a55..54a711a 100644 (file)
@@ -1457,7 +1457,7 @@ implicit_conversion (tree to, tree from, tree expr, bool c_cast_p,
          tree elt;
 
          if (nelts == 0)
-           elt = integer_zero_node;
+           elt = build_value_init (to, tf_none);
          else if (nelts == 1)
            elt = CONSTRUCTOR_ELT (expr, 0)->value;
          else
@@ -5050,7 +5050,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
        {
          int nelts = CONSTRUCTOR_NELTS (expr);
          if (nelts == 0)
-           expr = integer_zero_node;
+           expr = build_value_init (totype, tf_warning_or_error);
          else if (nelts == 1)
            expr = CONSTRUCTOR_ELT (expr, 0)->value;
          else
index 2cfe379..da06cd3 100644 (file)
@@ -1,5 +1,7 @@
 2010-09-06  Jason Merrill  <jason@redhat.com>
 
+       * g++.dg/cpp0x/initlist42.C: New.
+
        * g++.dg/cpp0x/auto19.C: New.
 
        * g++.dg/template/sfinae25.C: New.
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist42.C b/gcc/testsuite/g++.dg/cpp0x/initlist42.C
new file mode 100644 (file)
index 0000000..e63959d
--- /dev/null
@@ -0,0 +1,13 @@
+// { dg-options -std=c++0x }
+
+enum Unscoped { };
+enum class Scoped { };
+
+Unscoped bar(Unscoped x) { return x; }
+Scoped bar(Scoped x) { return x; }
+
+auto var1u = bar(Unscoped()); // OK
+auto var1s = bar(Scoped()); // OK
+
+auto var2u = bar(Unscoped{}); // #1 Error, but should work
+auto var2s = bar(Scoped{}); // #2 Error, but should work