Date: Tue, 25 Feb 2025 23:07:44 +0100
On 25/02/2025 22.18, Jonas Christen via Std-Proposals wrote:
> Designated initializers are only allowed for direct non-static data members right now as the standard says:
>
> > [...] the identifier in each designator shall name a direct non-static data member of the class [...]
>
> and I couldn't find any explicit reasoning for this decision in P0329R4: "Designated Initialization Wording".
>
> I'm not a language/compiler expert, so not sure if there would be any certain problems with dropping the "direct" here (or maybe rewording it differently ofc) and implementing it, so please let me know if there are.
Maybe you want this:
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2287r3.html
which does away with the using-declarations, too.
Jens
> Basically I want something like this to compile:
>
> struct ta{ int a; };
> struct tb{ int b; };
> struct tc : ta, tb{
> using ta::a;
> using tb::b;
> int c;
> };
> struct td{ int a; int b; int c; };
> int main(){
> // OK
> td ok{ .a = 1, .b = 2, .c = 3 };
>
> // Error: 'ta::a' is not a direct member of 'tc'
> // would be allowed with relaxed rules for designated-initializers
> ta err{ .a = 1, .b = 2, .c = 3 };
> }
>
>
> - Jonas
>
> Designated initializers are only allowed for direct non-static data members right now as the standard says:
>
> > [...] the identifier in each designator shall name a direct non-static data member of the class [...]
>
> and I couldn't find any explicit reasoning for this decision in P0329R4: "Designated Initialization Wording".
>
> I'm not a language/compiler expert, so not sure if there would be any certain problems with dropping the "direct" here (or maybe rewording it differently ofc) and implementing it, so please let me know if there are.
Maybe you want this:
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p2287r3.html
which does away with the using-declarations, too.
Jens
> Basically I want something like this to compile:
>
> struct ta{ int a; };
> struct tb{ int b; };
> struct tc : ta, tb{
> using ta::a;
> using tb::b;
> int c;
> };
> struct td{ int a; int b; int c; };
> int main(){
> // OK
> td ok{ .a = 1, .b = 2, .c = 3 };
>
> // Error: 'ta::a' is not a direct member of 'tc'
> // would be allowed with relaxed rules for designated-initializers
> ta err{ .a = 1, .b = 2, .c = 3 };
> }
>
>
> - Jonas
>
Received on 2025-02-25 22:07:58