[C++ Patch] PR 51219

Paolo Carlini paolo.carlini@oracle.com
Mon Jan 27 15:26:00 GMT 2014


Hi,

as explained by Richard in the audit trail of the duplicate c++/54808, 
the problem here is that the type checking code notices that we are 
initializing the unnamed bit-field with a bare integer_zero_node. 
Calling here too cp_convert_and_check works.

Tested x86_64-linux (probably not worth backporting because, as 
explained, can only happen with checking enabled)

Thanks,
Paolo.

///////////////////
-------------- next part --------------
/cp
2014-01-27

	PR c++/51219
	* typeck2.c (process_init_constructor_record): Use cp_convert_and_check
	for unnamed bit-fields.

/testsuite
2014-01-27

	PR c++/51219
	* g++.dg/init/bitfield5.C: New.
-------------- next part --------------
Index: cp/typeck2.c
===================================================================
--- cp/typeck2.c	(revision 207127)
+++ cp/typeck2.c	(working copy)
@@ -1269,8 +1269,10 @@ process_init_constructor_record (tree type, tree i
 
       if (!DECL_NAME (field) && DECL_C_BIT_FIELD (field))
 	{
-	  flags |= picflag_from_initializer (integer_zero_node);
-	  CONSTRUCTOR_APPEND_ELT (v, field, integer_zero_node);
+	  next = cp_convert_and_check (TREE_TYPE (field), integer_zero_node,
+				       complain);
+	  flags |= picflag_from_initializer (next);
+	  CONSTRUCTOR_APPEND_ELT (v, field, next);
 	  continue;
 	}
 
Index: testsuite/g++.dg/init/bitfield5.C
===================================================================
--- testsuite/g++.dg/init/bitfield5.C	(revision 0)
+++ testsuite/g++.dg/init/bitfield5.C	(working copy)
@@ -0,0 +1,12 @@
+// PR c++/51219
+
+struct A
+{
+  int i;
+  int : 8;
+};
+
+void foo()
+{
+  A a = { 0 };
+}


More information about the Gcc-patches mailing list