Date: Tue, 16 Jun 2026 13:08:18 +0300
On Tue Jun 16, 2026 at 2:15 AM EEST, Halalaluyafail3 wrote:
> On Mon, Jun 15, 2026 at 6:43 PM Radu Ungureanu via Std-Proposals
> <std-proposals_at_[hidden]> wrote:
>>
>> Hi all,
>>
>> I want to propose allowing direct-list-initialization syntax for default
>> function arguments.
>>
>> Currently, if a type X has an explicit constructor:
>>
>> struct X {
>> explicit X(int) {}
>> };
>>
>> a default argument can be specified like this:
>>
>> void f(X x = X{5}) {}
>>
>> My proposal would allow the following:
>>
>> void f(X x{5}) {}
>>
>> With semantics equivalent to:
>>
>> void f(X x = X{5}) {}
>>
>> While I am aware this does not add new expressive power, the motivation
>> is to use direct-list-initialization style syntax for default arguments
>> without requiring the repetition of the parameter type.
>>
>> I'd appreciate some feedback on the usefulness of such a feature and any
>> issues with the proposed semantics or syntax.
>
> Consider unnamed parameters:
>
> X f(X=X{5});
>
> This is currently ok, but so is:
>
> X g(X{5});
>
> This is not a function, however. With the current disambiguation rules,
> expanding default initializers in this way would change it to a function.
You bring up a good point, but I think that this can be solved by making
it only for named parameters only. For example:
void f(X x{5}); // OK
void f(X {5}); // Not allowed by the proposed syntax
This would avoid changing the current disambiguation rules for something
like:
X g(X{5});
which would continue to be parsed as it is today. Otherwise, the
disambiguation would have to get even more complex and could possibly
break existing code.
> On Mon, Jun 15, 2026 at 6:43 PM Radu Ungureanu via Std-Proposals
> <std-proposals_at_[hidden]> wrote:
>>
>> Hi all,
>>
>> I want to propose allowing direct-list-initialization syntax for default
>> function arguments.
>>
>> Currently, if a type X has an explicit constructor:
>>
>> struct X {
>> explicit X(int) {}
>> };
>>
>> a default argument can be specified like this:
>>
>> void f(X x = X{5}) {}
>>
>> My proposal would allow the following:
>>
>> void f(X x{5}) {}
>>
>> With semantics equivalent to:
>>
>> void f(X x = X{5}) {}
>>
>> While I am aware this does not add new expressive power, the motivation
>> is to use direct-list-initialization style syntax for default arguments
>> without requiring the repetition of the parameter type.
>>
>> I'd appreciate some feedback on the usefulness of such a feature and any
>> issues with the proposed semantics or syntax.
>
> Consider unnamed parameters:
>
> X f(X=X{5});
>
> This is currently ok, but so is:
>
> X g(X{5});
>
> This is not a function, however. With the current disambiguation rules,
> expanding default initializers in this way would change it to a function.
You bring up a good point, but I think that this can be solved by making
it only for named parameters only. For example:
void f(X x{5}); // OK
void f(X {5}); // Not allowed by the proposed syntax
This would avoid changing the current disambiguation rules for something
like:
X g(X{5});
which would continue to be parsed as it is today. Otherwise, the
disambiguation would have to get even more complex and could possibly
break existing code.
Received on 2026-06-16 10:08:22
