From 0bdc4c1ce9470d4b5b926d2d62ba3ed243775d9e Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Fri, 18 Nov 2016 15:27:26 -0500 Subject: [PATCH] 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. From-SVN: r242603 --- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/cp-tree.h | 2 +- gcc/cp/semantics.c | 3 ++- gcc/cp/typeck2.c | 8 ++++---- gcc/testsuite/g++.dg/cpp0x/initlist-explicit1.C | 11 +++++++++++ 5 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/initlist-explicit1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 21a1830..68431bb 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2016-11-18 Jason Merrill + + 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 Alan Hayward David Sherwood diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index e5f9113..5674886 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -6839,7 +6839,7 @@ extern tree store_init_value (tree, tree, vec**, 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, diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 96c67a5..389e7f1 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -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; diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index 2ca4bf2..b214c99 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -794,7 +794,7 @@ store_init_value (tree decl, tree init, vec** 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 index 0000000..5e00b2d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist-explicit1.C @@ -0,0 +1,11 @@ +// PR c++/67631 +// { dg-do compile { target c++11 } } + +struct X +{ + explicit operator unsigned (); +}; +unsigned foo () +{ + return unsigned{ X () }; +} -- 2.7.4