public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jsm28 at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/63944] New: [DR#413] Partial overriding of nonconstant struct/union initializers with designated initializers
Date: Wed, 19 Nov 2014 00:31:00 -0000	[thread overview]
Message-ID: <bug-63944-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 63944
           Summary: [DR#413] Partial overriding of nonconstant
                    struct/union initializers with designated initializers
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jsm28 at gcc dot gnu.org
                CC: jakub at gcc dot gnu.org

C11 DR#413 has now moved to closed (see N1892).  This says that if an
initializer (a) initializes a struct or union member of a larger object using
an expression of that struct or union type and (b) then uses a designated
initializer to override just part of that struct or union initialization, then
the overriding does not affect the initialization of the rest of the struct or
union.  Thus, the following should pass (based on the test in the DR):

extern void exit (int);
extern void abort (void);
typedef struct {
int k;
int l;
int a[2];
} T;

typedef struct {
int i;
T t;
} S;

T x = {.l = 43, .k = 42, .a[1] = 19, .a[0] = 18 };

int
main (void)
{
S l = { 1, .t = x, .t.l = 41, .t.a[1] = 17};
if (l.t.k == 42) exit (0); else abort ();
}

Clearly the existing approach for string constants (of splitting them
individual characters) won't work here (but is still needed for initializers of
objects with static storage duration).  This bug is specific to initializers of
objects with automatic storage duration; it can apply both to initialization
with an expression of struct type, and to initialization with one of union type
(in the union case, the override would have to be of just part of a union
member, as setting the whole of a union member sets the whole union).  I
suppose some initializations with such partial overriding need to generate more
complicated code - one possibility might be for such partial overriding to
replace the initializer for .t with (tmp = x, tmp.l = 41, tmp) for a new
temporary variable tmp.


             reply	other threads:[~2014-11-19  0:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-19  0:31 jsm28 at gcc dot gnu.org [this message]
2014-11-19  0:42 ` [Bug c/63944] " joseph at codesourcery dot com
2014-11-19  9:06 ` jakub at gcc dot gnu.org
2020-03-19 21:00 ` [Bug c/63944] [DR413] " jsm28 at gcc dot gnu.org
2021-01-05 16:57 ` mpolacek 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-63944-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).