User account creation filtered due to spam.

Bug 48537 - [4.6/4.7 regression] C++0x: ICE using union with non-trivial member
Summary: [4.6/4.7 regression] C++0x: ICE using union with non-trivial member
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 4.6.1
Assignee: Jason Merrill
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-10 03:17 UTC by Simon Hill
Modified: 2011-04-18 23:56 UTC (History)
1 user (show)

See Also:
Host:
Target: x86_64-unknown-linux-gnu
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-04-18 17:44:00


Attachments
Test source - ICEs. (76 bytes, text/x-c++src)
2011-04-10 03:17 UTC, Simon Hill
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Hill 2011-04-10 03:17:27 UTC
Created attachment 23936 [details]
Test source - ICEs.

If a union contains a member with a non-trivial default constructor, attempting to explicitly call (or decltype) the default constructor results in an ICE.
(This relates to http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2544.pdf, implemented in GCC 4.6)

Simplest example (attached).
====== union-non-trivial-member-simple.cpp ========
struct SFoo
	{
		SFoo() =delete;
	};

union UFoo
	{
		SFoo foo;
	};

int main()
	{
		UFoo();
	}
====================================================
> g++ union-non-trivial-member-simple.cpp -std=c++0x
====================================================
../union-non-trivial-member-simple.cpp: In function ‘int main()’:
../union-non-trivial-member-simple.cpp:13:8: internal compiler error: in build_value_init_noctor, at cp/init.c:374
====================================================

NOTE: Line may not be 374 for you.
I've indicated the line here:
=========== cp/init.c ==============
build_value_init_noctor (tree type, tsubst_flags_t complain)
{
  if (CLASS_TYPE_P (type))
    {
      gcc_assert (!TYPE_NEEDS_CONSTRUCTING (type)); // (<---- THIS LINE!!!!!!
	
      if (TREE_CODE (type) != UNION_TYPE)
	{
====================================

- Works as expected (error but no ICE) with copy constructor, assignment or destructor.
- Works as expected (error but no ICE) for implicit declaration (eg: "UFoo foo;").
- Can reject valid code if using SFINAE.



USEFULNESS:
I am attempting to use SFINAE (using decltype) on a template union containing a given type to determine the trivial-ness of the given type's special member functions.

[C++ standard:9.5.2]
"...[Note: If any non-static data member of a union has a non-trivial default constructor (12.1 [class.ctor]), copy constructor (12.8 [class.copy]), copy assignment operator (12.8 [class.copy]), or destructor (12.4 [class.dtor]), the corresponding member function of the union must be user-declared or it will be implicitly deleted (8.4 [dcl.fct.def]) for the union. —end note]"

Which (I hope) should allow classifications like "trivial class" to be calculated without relying on compiler-specific stuff.



SPECS:
gcc: version 4.7.0 2011-04-05 (experimental) (svn = 171986)
gcc: version 4.6.0 2011-02-13 (experimental) (svn = 170074)
 - tested with both.
 - both GCCs manually patched by
(http://gcc.gnu.org/ml/gcc-patches/2007-04/msg00620.html)
 - patch is unlikely to have any effect.
ubuntu: 10.10 (64 bit)
intel: core2 duo


HTH.
Simon.
Comment 1 Jason Merrill 2011-04-18 22:40:48 UTC
Author: jason
Date: Mon Apr 18 22:40:43 2011
New Revision: 172678

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=172678
Log:
	PR c++/48537
	* init.c (build_value_init): Handle UNION_TYPE the same.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/union4.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/init.c
    trunk/gcc/testsuite/ChangeLog
Comment 2 Jason Merrill 2011-04-18 23:29:33 UTC
Author: jason
Date: Mon Apr 18 23:29:30 2011
New Revision: 172679

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=172679
Log:
	PR c++/48537
	* init.c (build_value_init): Handle UNION_TYPE the same.

Added:
    branches/gcc-4_6-branch/gcc/testsuite/g++.dg/cpp0x/union4.C
Modified:
    branches/gcc-4_6-branch/gcc/cp/ChangeLog
    branches/gcc-4_6-branch/gcc/cp/init.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Comment 3 Jason Merrill 2011-04-18 23:56:20 UTC
Fixed.