public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "yacwroy at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/48537] New: C++0x: ICE using union with non-trivial member
Date: Sun, 10 Apr 2011 03:17:00 -0000	[thread overview]
Message-ID: <bug-48537-4@http.gcc.gnu.org/bugzilla/> (raw)

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: unassigned@gcc.gnu.org
        ReportedBy: yacwroy@gmail.com
            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.


             reply	other threads:[~2011-04-10  3:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-10  3:17 yacwroy at gmail dot com [this message]
2011-04-18 17:44 ` [Bug c++/48537] " jason at gcc dot gnu.org
2011-04-18 22:41 ` jason at gcc dot gnu.org
2011-04-18 23:29 ` [Bug c++/48537] [4.6/4.7 regression] " jason at gcc dot gnu.org
2011-04-18 23:56 ` jason at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-48537-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).