PR c++/67631 - list-init and explicit conversions
authorJason Merrill <jason@redhat.com>
Fri, 18 Nov 2016 20:27:26 +0000 (15:27 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 18 Nov 2016 20:27:26 +0000 (15:27 -0500)
* semantics.c (finish_compound_literal): Call digest_init_flags.
* typeck2.c (digest_init_flags): Add complain parm.
(store_init_value): Pass it.

From-SVN: r242603

gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/semantics.c
gcc/cp/typeck2.c
gcc/testsuite/g++.dg/cpp0x/initlist-explicit1.C [new file with mode: 0644]

index 21a1830..68431bb 100644 (file)
@@ -1,3 +1,10 @@
+2016-11-18  Jason Merrill  <jason@redhat.com>
+
+       PR c++/67631 - list-init and explicit conversions
+       * semantics.c (finish_compound_literal): Call digest_init_flags.
+       * typeck2.c (digest_init_flags): Add complain parm.
+       (store_init_value): Pass it.
+
 2016-11-18  Richard Sandiford  <richard.sandiford@arm.com>
            Alan Hayward  <alan.hayward@arm.com>
            David Sherwood  <david.sherwood@arm.com>
index e5f9113..5674886 100644 (file)
@@ -6839,7 +6839,7 @@ extern tree store_init_value                      (tree, tree, vec<tree, va_gc>**, int);
 extern tree split_nonconstant_init             (tree, tree);
 extern bool check_narrowing                    (tree, tree, tsubst_flags_t);
 extern tree digest_init                                (tree, tree, tsubst_flags_t);
-extern tree digest_init_flags                  (tree, tree, int);
+extern tree digest_init_flags                  (tree, tree, int, tsubst_flags_t);
 extern tree digest_nsdmi_init                  (tree, tree);
 extern tree build_scoped_ref                   (tree, tree, tree *);
 extern tree build_x_arrow                      (location_t, tree,
index 96c67a5..389e7f1 100644 (file)
@@ -2713,7 +2713,8 @@ finish_compound_literal (tree type, tree compound_literal,
       if (type == error_mark_node)
        return error_mark_node;
     }
-  compound_literal = digest_init (type, compound_literal, complain);
+  compound_literal = digest_init_flags (type, compound_literal, LOOKUP_NORMAL,
+                                       complain);
   if (TREE_CODE (compound_literal) == CONSTRUCTOR)
     TREE_HAS_CONSTRUCTOR (compound_literal) = true;
 
index 2ca4bf2..b214c99 100644 (file)
@@ -794,7 +794,7 @@ store_init_value (tree decl, tree init, vec<tree, va_gc>** cleanups, int flags)
     value = init;
   else
     /* Digest the specified initializer into an expression.  */
-    value = digest_init_flags (type, init, flags);
+    value = digest_init_flags (type, init, flags, tf_warning_or_error);
 
   value = extend_ref_init_temps (decl, value, cleanups);
 
@@ -1165,9 +1165,9 @@ digest_init (tree type, tree init, tsubst_flags_t complain)
 }
 
 tree
-digest_init_flags (tree type, tree init, int flags)
+digest_init_flags (tree type, tree init, int flags, tsubst_flags_t complain)
 {
-  return digest_init_r (type, init, false, flags, tf_warning_or_error);
+  return digest_init_r (type, init, false, flags, complain);
 }
 
 /* Process the initializer INIT for an NSDMI DECL (a FIELD_DECL).  */
@@ -1183,7 +1183,7 @@ digest_nsdmi_init (tree decl, tree init)
   if (BRACE_ENCLOSED_INITIALIZER_P (init)
       && CP_AGGREGATE_TYPE_P (type))
     init = reshape_init (type, init, tf_warning_or_error);
-  init = digest_init_flags (type, init, flags);
+  init = digest_init_flags (type, init, flags, tf_warning_or_error);
   if (TREE_CODE (init) == TARGET_EXPR)
     /* This represents the whole initialization.  */
     TARGET_EXPR_DIRECT_INIT_P (init) = true;
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-explicit1.C b/gcc/testsuite/g++.dg/cpp0x/initlist-explicit1.C
new file mode 100644 (file)
index 0000000..5e00b2d
--- /dev/null
@@ -0,0 +1,11 @@
+// PR c++/67631
+// { dg-do compile { target c++11 } }
+
+struct X
+{
+  explicit operator unsigned ();
+};
+unsigned foo ()
+{
+  return unsigned{ X () };
+}