Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dcl.init.aggr]/4.1 designated-initializer-list vs initializer-clause #4898

Open
xmh0511 opened this issue Sep 13, 2021 · 0 comments
Open

[dcl.init.aggr]/4.1 designated-initializer-list vs initializer-clause #4898

xmh0511 opened this issue Sep 13, 2021 · 0 comments

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Sep 13, 2021

For each explicitly initialized element:

  • If the element is an anonymous union member and the initializer list is a brace-enclosed designated-initializer-list, the element is initialized by the designated-initializer-list { D }, where D is the designated-initializer-clause naming a member of the anonymous union member. There shall be only one such designated-initializer-clause.

How could designated-initializer-list be the form { D }? According to the grammar of designated-initializer-list, it should be the comma-separated list of .identifier brace-or-equal-initializer. The above rule seems to phrase the following example

struct C{
   union {
     int a;
   };
};
C c = {{.a = 0}};

In this example, the corresponding initializer of the anonymous union member is the initializer-clasuse, which is a brace-enclosed designated-initializer-list. However, the formal example under [dcl.init.aggr]/4.1 is that

struct C {
  union {
    int a;
    const char* p;
  };
  int x;
} c = { .a = 1, .x = 3 };

That is, the original intent of the above rule is used to phrase the case where the explicitly initialized element is an anonymous union member and the corresponding initializer is a designated-initializer-clause naming the member of it. Should we reword the rule to that

If the element is an anonymous union member and the initializer D is a designated-initializer-clause naming a member of the anonymous union member, the element is initialized by the initializer { D }. There shall be only one such designated-initializer-clause for the anonymous union member.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant