public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/48537 (ICE with value-initialization of union with deleted ctor)
@ 2011-04-18 23:56 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2011-04-18 23:56 UTC (permalink / raw)
  To: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 221 bytes --]

The check for UNION_TYPE predates the C++0x extension of unions to allow 
members with constructors; now we can have a union that needs 
non-trivial initialization.

Tested x86_64-pc-linux-gnu, applying to trunk and 4.6.

[-- Attachment #2: 48537.patch --]
[-- Type: text/plain, Size: 1180 bytes --]

commit 019dffcf98bb95ebbcb9180d76293b899d674ecf
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Apr 18 10:32:55 2011 -0700

    	PR c++/48537
    	* init.c (build_value_init): Handle UNION_TYPE the same.

diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 3280d9b..04d2bb2 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -343,7 +343,7 @@ build_value_init (tree type, tsubst_flags_t complain)
 				      NULL, type, LOOKUP_NORMAL,
 				      complain),
 	   complain);
-      else if (TREE_CODE (type) != UNION_TYPE && TYPE_NEEDS_CONSTRUCTING (type))
+      else if (TYPE_NEEDS_CONSTRUCTING (type))
 	{
 	  /* This is a class that needs constructing, but doesn't have
 	     a user-provided constructor.  So we need to zero-initialize
diff --git a/gcc/testsuite/g++.dg/cpp0x/union4.C b/gcc/testsuite/g++.dg/cpp0x/union4.C
new file mode 100644
index 0000000..0705047
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/union4.C
@@ -0,0 +1,17 @@
+// PR c++/48537
+// { dg-options -std=c++0x }
+
+struct SFoo
+{
+  SFoo() =delete;		// { dg-error "declared" }
+};
+
+union UFoo			// { dg-error "deleted" }
+{
+  SFoo foo;
+};
+
+int main()
+{
+  UFoo();			// { dg-error "deleted" }
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-04-18 23:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-18 23:56 C++ PATCH for c++/48537 (ICE with value-initialization of union with deleted ctor) Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).