On Fri, 24 Jan 2025, Martin Uecker wrote: > No doubt, but this is a semantic difference which does necessarily imply > that the syntax has to be different. The syntax of initialization seems > intentionally designed to look like assignment to be intuitive. > The "=" in designators otherwise seems to serve no useful purpose.
The first version of a proposal for designated initializers that's available online seems to be N494 (which doesn't give a rationale for the particular syntax choice). > My point was that this syntax, i.e. using __self__ instead of only > using a dot could have made sense for designators just as well. Or > in other words, there is no logical reason why designators have no > __self__ while counted_by would have it, except to be able to > distinguish between them purely based on syntax. > > But the parser can already distinguish between those cases by using > semantic information, so this is not needed if one does not insist > on context-freeness in this case (which we do not have anyway). So > in my opinion, the __self__ is not needed. I don't think you can in general distinguish based on semantic information, without some explicit (and ugly) disambiguation rule in the case where .IDENTIFIER = EXPRESSION is both inside an initializer list for a compound literal of a type with a corresponding member, and also inside counted_by for a structure with a corresponding member. As long as you have at most two of (designated initializers, compound literals, counted_by with expressions involving .IDENTIFIER to reference a member of the structure with the member using counted_by), there is no syntactic ambiguity (and so no need for extra notation such as __self__). Once you have all three of those features, it become possible to have syntax inside an initializer list for a compound literal inside a counted_by expression that could be interpreted either way, and so you need either disambiguating syntax or some other kind of disambiguation rule. -- Joseph S. Myers josmy...@redhat.com