Commit d664d76d by Jakub Jelinek Committed by Jakub Jelinek

Implement P0138R2, C++17 construction rules for enum class values

	Implement P0138R2, C++17 construction rules for enum class values
	* cp-tree.h (is_direct_enum_init): Declare.
	* decl.c (is_direct_enum_init): New function.
	(reshape_init): Use it.
	* typeck.c (convert_for_assignment): Likewise.

	* g++.dg/cpp1z/direct-enum-init1.C: New test.

From-SVN: r240449
parent 24cae8cb
2016-09-23 Jakub Jelinek <jakub@redhat.com>
Implement P0138R2, C++17 construction rules for enum class values
* cp-tree.h (is_direct_enum_init): Declare.
* decl.c (is_direct_enum_init): New function.
(reshape_init): Use it.
* typeck.c (convert_for_assignment): Likewise.
* Make-lang.in (check-c++1z): Pass RUNTESTFLAGS down to
make check-g++.
......
......@@ -5829,6 +5829,7 @@ extern tree check_elaborated_type_specifier (enum tag_types, tree, bool);
extern void warn_extern_redeclared_static (tree, tree);
extern tree cxx_comdat_group (tree);
extern bool cp_missing_noreturn_ok_p (tree);
extern bool is_direct_enum_init (tree, tree);
extern void initialize_artificial_var (tree, vec<constructor_elt, va_gc> *);
extern tree check_var_type (tree, tree);
extern tree reshape_init (tree, tree, tsubst_flags_t);
......
......@@ -5581,6 +5581,22 @@ next_initializable_field (tree field)
return field;
}
/* Return true for [dcl.init.list] direct-list-initialization from
single element of enumeration with a fixed underlying type. */
bool
is_direct_enum_init (tree type, tree init)
{
if (cxx_dialect >= cxx1z
&& TREE_CODE (type) == ENUMERAL_TYPE
&& ENUM_FIXED_UNDERLYING_TYPE_P (type)
&& TREE_CODE (init) == CONSTRUCTOR
&& CONSTRUCTOR_IS_DIRECT_INIT (init)
&& CONSTRUCTOR_NELTS (init) == 1)
return true;
return false;
}
/* Subroutine of reshape_init_array and reshape_init_vector, which does
the actual work. ELT_TYPE is the element type of the array. MAX_INDEX is an
INTEGER_CST representing the size of the array minus one (the maximum index),
......@@ -6026,6 +6042,17 @@ reshape_init (tree type, tree init, tsubst_flags_t complain)
if (vec_safe_is_empty (v))
return init;
/* Handle [dcl.init.list] direct-list-initialization from
single element of enumeration with a fixed underlying type. */
if (is_direct_enum_init (type, init))
{
tree elt = CONSTRUCTOR_ELT (init, 0)->value;
if (check_narrowing (ENUM_UNDERLYING_TYPE (type), elt, complain))
return cp_build_c_cast (type, elt, tf_warning_or_error);
else
return error_mark_node;
}
/* Recurse on this CONSTRUCTOR. */
d.cur = &(*v)[0];
d.end = d.cur + v->length ();
......
......@@ -8266,6 +8266,17 @@ convert_for_assignment (tree type, tree rhs,
if (TREE_CODE (rhs) == NON_LVALUE_EXPR)
rhs = TREE_OPERAND (rhs, 0);
/* Handle [dcl.init.list] direct-list-initialization from
single element of enumeration with a fixed underlying type. */
if (is_direct_enum_init (type, rhs))
{
tree elt = CONSTRUCTOR_ELT (rhs, 0)->value;
if (check_narrowing (ENUM_UNDERLYING_TYPE (type), elt, complain))
rhs = cp_build_c_cast (type, elt, complain);
else
rhs = error_mark_node;
}
rhstype = TREE_TYPE (rhs);
coder = TREE_CODE (rhstype);
......
2016-09-23 Jakub Jelinek <jakub@redhat.com>
Implement P0138R2, C++17 construction rules for enum class values
* g++.dg/cpp1z/direct-enum-init1.C: New test.
2016-09-23 David Malcolm <dmalcolm@redhat.com>
PR preprocessor/77672
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment