This came up in Reflection where an assert fails because we have two
different trees for same enumerators. The reason is that in
finish_enum_value_list we copy_node when converting the enumerators.
It should be more efficient to share trees for identical enumerators.
This fix was proposed by Jakub.
gcc/cp/ChangeLog:
* decl.cc (finish_enum_value_list): Use fold_convert instead of
copy_node.
Co-authored-by: Jakub Jelinek <jakub@redhat.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
value = perform_implicit_conversion (underlying_type,
DECL_INITIAL (decl),
tf_warning_or_error);
- /* Do not clobber shared ints. */
- if (value != error_mark_node)
- {
- value = copy_node (value);
+ /* Do not clobber shared ints. But do share identical enumerators. */
+ value = fold_convert (enumtype, value);
- TREE_TYPE (value) = enumtype;
- }
DECL_INITIAL (decl) = value;
if (export_p)
DECL_MODULE_EXPORT_P (decl) = true;