public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/57977] New: zero-length const array in union prohibits default copy xtor
@ 2013-07-25  5:32 daniel.santos at pobox dot com
  2013-07-25 14:07 ` [Bug c++/57977] " daniel.santos at pobox dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: daniel.santos at pobox dot com @ 2013-07-25  5:32 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57977

            Bug ID: 57977
           Summary: zero-length const array in union prohibits default
                    copy xtor
           Product: gcc
           Version: 4.7.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: daniel.santos at pobox dot com

#include <iostream>

union a {
    struct {
        const char string[0];
    } b;
};


int main(int argc, char *argv[]) {
    std::cout << "size = " << sizeof(union a) << std::endl;
    return 0;
}

Produces:

bug.cpp:6:4: error: member ‘a::<anonymous struct> a::b’ with copy assignment
operator not allowed in union
bug.cpp:6:4: note: unrestricted unions only available with -std=c++11 or
-std=gnu++11


So the zero-length array is, of course, a gcc extension.  I believe it is a bug
because it is zero-sized and no code needs to be generated to copy union
a::b::string.

My justification for using this is to aid in const correctness. I actually use
this in C in a kernel module where I create and populate it once and then
access it several times, so I just cast it as non-const when I populate it.  I
prefer to use the exact same header files for kernel & userland where possible.
>From gcc-bugs-return-426663-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Jul 25 05:37:38 2013
Return-Path: <gcc-bugs-return-426663-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 20926 invoked by alias); 25 Jul 2013 05:37:38 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 20840 invoked by uid 48); 25 Jul 2013 05:37:34 -0000
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/57977] zero-length const array in union prohibits default copy xtor
Date: Thu, 25 Jul 2013 05:37:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c++
X-Bugzilla-Version: 4.7.3
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: pinskia at gcc dot gnu.org
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-57977-4-UznmnoJbZQ@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-57977-4@http.gcc.gnu.org/bugzilla/>
References: <bug-57977-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2013-07/txt/msg01170.txt.bz2
Content-length: 268

http://gcc.gnu.org/bugzilla/show_bug.cgi?idW977

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
It is not the zero length which is causing the copy constructor to be created
but rather the const part which causes the copy constructor to happen.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/57977] zero-length const array in union prohibits default copy xtor
  2013-07-25  5:32 [Bug c++/57977] New: zero-length const array in union prohibits default copy xtor daniel.santos at pobox dot com
@ 2013-07-25 14:07 ` daniel.santos at pobox dot com
  2013-07-25 14:14 ` daniel.santos at pobox dot com
  2021-12-03 22:28 ` [Bug c++/57977] zero-length const array in union prohibits default copy ctor pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: daniel.santos at pobox dot com @ 2013-07-25 14:07 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57977

--- Comment #2 from Daniel Santos <daniel.santos at pobox dot com> ---
Don't you mean the part which prohibits its creation?


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/57977] zero-length const array in union prohibits default copy xtor
  2013-07-25  5:32 [Bug c++/57977] New: zero-length const array in union prohibits default copy xtor daniel.santos at pobox dot com
  2013-07-25 14:07 ` [Bug c++/57977] " daniel.santos at pobox dot com
@ 2013-07-25 14:14 ` daniel.santos at pobox dot com
  2021-12-03 22:28 ` [Bug c++/57977] zero-length const array in union prohibits default copy ctor pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: daniel.santos at pobox dot com @ 2013-07-25 14:14 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57977

--- Comment #3 from Daniel Santos <daniel.santos at pobox dot com> ---
Hmm, I guess it's actually the copy assignment operator.  Either way, it makes
sense if the const union member was "real", in this case, the copy assignment
for this member would be a no-op (were we to copy it as that type), so the
constness of this member should be ignored (as I understand it).


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/57977] zero-length const array in union prohibits default copy ctor
  2013-07-25  5:32 [Bug c++/57977] New: zero-length const array in union prohibits default copy xtor daniel.santos at pobox dot com
  2013-07-25 14:07 ` [Bug c++/57977] " daniel.santos at pobox dot com
  2013-07-25 14:14 ` daniel.santos at pobox dot com
@ 2021-12-03 22:28 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-03 22:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57977

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-12-03
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
           Keywords|                            |rejects-valid

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-12-03 22:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-25  5:32 [Bug c++/57977] New: zero-length const array in union prohibits default copy xtor daniel.santos at pobox dot com
2013-07-25 14:07 ` [Bug c++/57977] " daniel.santos at pobox dot com
2013-07-25 14:14 ` daniel.santos at pobox dot com
2021-12-03 22:28 ` [Bug c++/57977] zero-length const array in union prohibits default copy ctor pinskia at gcc dot gnu.org

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).