Bug 55606 - sorry, unimplemented: non-trivial designated initializers not supported
Summary: sorry, unimplemented: non-trivial designated initializers not supported
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: 8.0
Assignee: Not yet assigned to anyone
URL:
Keywords: FIXME, rejects-valid
: 77547 (view as bug list)
Depends on: 55227
Blocks:
  Show dependency treegraph
 
Reported: 2012-12-06 00:17 UTC by H.J. Lu
Modified: 2021-11-10 04:36 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.2.3, 4.3.4, 4.4.5, 4.8.0
Last reconfirmed: 2015-11-24 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2012-12-06 00:17:29 UTC
[hjl@gnu-6 build]$ cat x.c
struct foo {
  char x[128];
  unsigned* i;
};
struct foo x = {
    i: 0
};
[hjl@gnu-6 build]$ gcc -S x.c          
[hjl@gnu-6 build]$ g++ -S x.c     
x.c:7:1: sorry, unimplemented: non-trivial designated initializers not supported
[hjl@gnu-6 build]$
Comment 1 Paolo Carlini 2012-12-06 00:21:19 UTC
So? Do we have a plan of filing a PR for each sorry message?
Comment 2 H.J. Lu 2012-12-06 00:29:07 UTC
why does

struct foo x = {
    i: 0
};

work?
Comment 3 H.J. Lu 2012-12-06 00:30:11 UTC
BTW, clang works fine:

[hjl@gnu-6 tmp]$ /opt/llvm.old/bin/clang -c i.c
i.c:6:5: warning: use of GNU old-style field designator extension
      [-Wgnu-designator]
    i: 0
    ^~
    .i = 
1 warning generated.
[hjl@gnu-6 tmp]$
Comment 4 H.J. Lu 2012-12-06 00:32:46 UTC
[hjl@gnu-6 tmp]$ cat i.cc
struct foo {
  char x[128];
  unsigned* i;
};
struct foo x = {
    .i = 0
};
[hjl@gnu-6 tmp]$ /opt/llvm.old/bin/clang -c i.cc
[hjl@gnu-6 tmp]$ g++ -c i.cc
i.cc:7:1: sorry, unimplemented: non-trivial designated initializers not supported
[hjl@gnu-6 tmp]$
Comment 5 H.J. Lu 2012-12-06 00:35:38 UTC
This works:

[hjl@gnu-6 tmp]$ cat i.cc
struct foo {
  char x[128];
  unsigned* i;
};
struct foo x = {
    "foo",
    .i = 0
};
[hjl@gnu-6 tmp]$ g++ -c i.cc
[hjl@gnu-6 tmp]$
Comment 6 Paolo Carlini 2012-12-06 00:35:53 UTC
I'm not saying that some work should not be done, I'm saying that sorry message normally correspond to *known* issues, we don't need PRs for those, more or less by definition. But what can I tell you, if you like to have a PR for this, let's have it.
Comment 7 Andrew Pinski 2012-12-09 00:33:13 UTC
Confirmed.
Comment 9 Martin Sebor 2015-11-24 23:04:20 UTC
A similar test case not involving arrays:

$ cat z.c && /build/gcc-trunk-svn/gcc/xgcc -B /build/gcc-trunk-svn/gcc -S -Wall -Wextra -o/dev/null -xc++ z.c
typedef struct A {
    int i;
    struct { int a, b; } s;
} A;

A a = { 1, .s = { 2, 3 } };
A b = { .i = 1, .s = { 2, 3 } };
A c = { .s = { 2, 3 }, .i = 1 };
z.c:8:31: sorry, unimplemented: non-trivial designated initializers not supported
 A c = { .s = { 2, 3 }, .i = 1 };
                               ^

z.c:8:31: sorry, unimplemented: non-trivial designated initializers not supported
Comment 10 Andrew Pinski 2016-09-10 08:11:43 UTC
*** Bug 77547 has been marked as a duplicate of this bug. ***
Comment 11 nightstrike 2018-07-10 13:18:47 UTC
This now works with gcc 8.  I haven't tried other versions.
Comment 12 nightstrike 2018-07-10 13:22:50 UTC
(In reply to Martin Sebor from comment #9)
> A similar test case not involving arrays:
> 
> $ cat z.c && /build/gcc-trunk-svn/gcc/xgcc -B /build/gcc-trunk-svn/gcc -S
> -Wall -Wextra -o/dev/null -xc++ z.c
> typedef struct A {
>     int i;
>     struct { int a, b; } s;
> } A;
> 
> A a = { 1, .s = { 2, 3 } };
> A b = { .i = 1, .s = { 2, 3 } };
> A c = { .s = { 2, 3 }, .i = 1 };
> z.c:8:31: sorry, unimplemented: non-trivial designated initializers not
> supported
>  A c = { .s = { 2, 3 }, .i = 1 };
>                                ^
> 
> z.c:8:31: sorry, unimplemented: non-trivial designated initializers not
> supported


This fails differently:

b.cc:8:31: error: designator order for field 'A::i' does not match declaration order in 'A'
 A c = { .s = { 2, 3 }, .i = 1 };
                               ^

But commenting out that line makes the rest work fine.
Comment 13 Andrew Pinski 2021-11-10 04:36:24 UTC
C++20 added this support, G++ supports mixing styles by default but not out of order. It was explicitly decided not support out of order.
So closing as fixed for GCC 8.