Patchwork [C++] PR 54922

login
register
mail settings
Submitter Paolo Carlini
Date Oct. 22, 2012, 10:45 p.m.
Message ID <5085CC6F.8000908@oracle.com>
Download mbox | patch
Permalink /patch/193298/
State New
Headers show

Comments

Paolo Carlini - Oct. 22, 2012, 10:45 p.m.
Hi,

today I spent quite a bit of time on this reject legal issue filed by 
Daniel, having to do with constrexpr constructors and anonymous union 
members: I didn't want to make the loop much more complex but we have to 
handle correctly multiple anonymous union too and of course produce 
correct diagnostics in all cases (eg, together with multiple members 
initialization diagnostics too). I figured out the below. Tested 
x86_64-linux, as usual.

Thanks,
Paolo.

////////////////////////
/cp
2012-10-22  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/54922
	* semantics.c (cx_check_missing_mem_inits): Handle anonymous union
	members.

/testsuite
2012-10-22  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/54922
	* g++.dg/cpp0x/constexpr-union4.C: New.
Jason Merrill - Oct. 23, 2012, 5:55 p.m.
OK.

Jason
Paolo Carlini - Nov. 7, 2012, 11:21 a.m.
On 10/23/2012 07:55 PM, Jason Merrill wrote:
> OK.
Unfortunately the patch as-is seems at least incomplete, thus to be sure 
I reverted it for now and re-opened the PR: trying to actually use the 
type showed issues in the gimplifier, see below. If you have hints about 
that I would be glad to further look into the issue (but, honestly, this 
isn't a regression, I don't think it can be considered an high priority 
issue now)

Thanks,
Paolo.

//////////////////

54922.C: In function ‘int main()’:
54922.C:14:16: internal compiler error: in gimplify_init_ctor_eval, at 
gimplify.c:3787
    nullable_int n;
                 ^
0x974d3a gimplify_init_ctor_eval
         /scratch/Gcc/svn-dirs/trunk/gcc/gimplify.c:3787
0x967c06 gimplify_init_constructor
         /scratch/Gcc/svn-dirs/trunk/gcc/gimplify.c:4145
0x9688bf gimplify_modify_expr_rhs
         /scratch/Gcc/svn-dirs/trunk/gcc/gimplify.c:4530
0x968cb1 gimplify_modify_expr
         /scratch/Gcc/svn-dirs/trunk/gcc/gimplify.c:4840
0x96a3f0 gimplify_expr(tree_node**, gimple_statement_d**, 
gimple_statement_d**, bool (*)(tree_node*), int)
         /scratch/Gcc/svn-dirs/trunk/gcc/gimplify.c:7167
0x972b66 gimplify_stmt(tree_node**, gimple_statement_d**)
         /scratch/Gcc/svn-dirs/trunk/gcc/gimplify.c:5700
0x975339 gimplify_and_add
         /scratch/Gcc/svn-dirs/trunk/gcc/gimplify.c:371
0x975339 gimplify_decl_expr
         /scratch/Gcc/svn-dirs/trunk/gcc/gimplify.c:1484
0x96aa5a gimplify_expr(tree_node**, gimple_statement_d**, 
gimple_statement_d**, bool (*)(tree_node*), int)
         /scratch/Gcc/svn-dirs/trunk/gcc/gimplify.c:7334
0x972b66 gimplify_stmt(tree_node**, gimple_statement_d**)
         /scratch/Gcc/svn-dirs/trunk/gcc/gimplify.c:5700
0x96c4dc gimplify_cleanup_point_expr
         /scratch/Gcc/svn-dirs/trunk/gcc/gimplify.c:5477
0x96c4dc gimplify_expr(tree_node**, gimple_statement_d**, 
gimple_statement_d**, bool (*)(tree_node*), int)
         /scratch/Gcc/svn-dirs/trunk/gcc/gimplify.c:7504
0x972b66 gimplify_stmt(tree_node**, gimple_statement_d**)
         /scratch/Gcc/svn-dirs/trunk/gcc/gimplify.c:5700
0x973ae5 gimplify_bind_expr
         /scratch/Gcc/svn-dirs/trunk/gcc/gimplify.c:1230
0x96a44a gimplify_expr(tree_node**, gimple_statement_d**, 
gimple_statement_d**, bool (*)(tree_node*), int)
         /scratch/Gcc/svn-dirs/trunk/gcc/gimplify.c:7338
0x972b66 gimplify_stmt(tree_node**, gimple_statement_d**)
         /scratch/Gcc/svn-dirs/trunk/gcc/gimplify.c:5700
0x96b4ab gimplify_statement_list
         /scratch/Gcc/svn-dirs/trunk/gcc/gimplify.c:1537
0x96b4ab gimplify_expr(tree_node**, gimple_statement_d**, 
gimple_statement_d**, bool (*)(tree_node*), int)
         /scratch/Gcc/svn-dirs/trunk/gcc/gimplify.c:7556
0x972b66 gimplify_stmt(tree_node**, gimple_statement_d**)
         /scratch/Gcc/svn-dirs/trunk/gcc/gimplify.c:5700
0x972c7e gimplify_body(tree_node*, bool)
         /scratch/Gcc/svn-dirs/trunk/gcc/gimplify.c:8200

Patch

Index: testsuite/g++.dg/cpp0x/constexpr-union4.C
===================================================================
--- testsuite/g++.dg/cpp0x/constexpr-union4.C	(revision 0)
+++ testsuite/g++.dg/cpp0x/constexpr-union4.C	(working copy)
@@ -0,0 +1,13 @@ 
+// PR c++/54922
+// { dg-do compile { target c++11 } }
+
+class nullable_int
+{
+  bool init_;
+  union {
+    unsigned char for_value_init;
+    int value_;
+  };
+public:
+  constexpr nullable_int() : init_(false), for_value_init() {}
+};
Index: cp/semantics.c
===================================================================
--- cp/semantics.c	(revision 192692)
+++ cp/semantics.c	(working copy)
@@ -6139,17 +6139,23 @@  cx_check_missing_mem_inits (tree fun, tree body, b
   for (i = 0; i <= nelts; ++i)
     {
       tree index;
+      tree anon_union_init_type = NULL_TREE;
       if (i == nelts)
 	index = NULL_TREE;
       else
 	{
 	  index = CONSTRUCTOR_ELT (body, i)->index;
+	  /* Handle anonymous union members.  */
+	  if (TREE_CODE (index) == COMPONENT_REF
+	      && ANON_UNION_TYPE_P (TREE_TYPE (TREE_OPERAND (index, 0))))
+	    anon_union_init_type = TREE_TYPE (TREE_OPERAND (index, 0));
 	  /* Skip base and vtable inits.  */
-	  if (TREE_CODE (index) != FIELD_DECL
-	      || DECL_ARTIFICIAL (index))
+	  else if (TREE_CODE (index) != FIELD_DECL
+		   || DECL_ARTIFICIAL (index))
 	    continue;
 	}
-      for (; field != index; field = DECL_CHAIN (field))
+      for (; field != index && TREE_TYPE (field) != anon_union_init_type;
+	   field = DECL_CHAIN (field))
 	{
 	  tree ftype;
 	  if (TREE_CODE (field) != FIELD_DECL