http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48537
Summary: C++0x: ICE using union with non-trivial member
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: [email protected]
ReportedBy: [email protected]
Target: x86_64-unknown-linux-gnu
Created attachment 23936
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=23936
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.