While working on C++17 evaluation order, I noticed that
get_target_expr was breaking on bit-fields because it tried to create
a temporary object of bit-field type, which doesn't exist in C++.  If
we copy a bit-field into a temporary it should have the real type of
the expression.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit 2ffdeb7351c5c9c758a24bbdc549b42410c0ddb4
Author: Jason Merrill <ja...@redhat.com>
Date:   Thu Jun 16 00:28:03 2016 -0400

    	Fix get_target_expr for bit-field expressions.
    
    	* tree.c (get_target_expr_sfinae): Handle bit-fields.
    	(build_target_expr): Call mark_rvalue_use.

diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c
index 6010f63..fa8db0a 100644
--- a/gcc/cp/tree.c
+++ b/gcc/cp/tree.c
@@ -377,6 +377,8 @@ build_target_expr (tree decl, tree value, tsubst_flags_t complain)
   tree t;
   tree type = TREE_TYPE (decl);
 
+  value = mark_rvalue_use (value);
+
   gcc_checking_assert (VOID_TYPE_P (TREE_TYPE (value))
 		       || TREE_TYPE (decl) == TREE_TYPE (value)
 		       /* On ARM ctors return 'this'.  */
@@ -729,7 +731,10 @@ get_target_expr_sfinae (tree init, tsubst_flags_t complain)
   else if (TREE_CODE (init) == VEC_INIT_EXPR)
     return build_target_expr (VEC_INIT_EXPR_SLOT (init), init, complain);
   else
-    return build_target_expr_with_type (init, TREE_TYPE (init), complain);
+    {
+      init = convert_bitfield_to_declared_type (init);
+      return build_target_expr_with_type (init, TREE_TYPE (init), complain);
+    }
 }
 
 tree

Reply via email to