why does a constructor with default arguments fail to match, when default construction is disabled?

user1234 user1234 at 12.de
Sat Aug 22 09:08:14 UTC 2026


On Saturday, 22 August 2026 at 05:50:00 UTC, DanielG wrote:
> here's another version of the code with reduced comments for 
> easier reading on the website:
>
> ```
> import std.stdio;
>
> class MyClass {
> 	@disable this();
>
> 	this(string y = "hi") {
> 		writeln("hello from MyClass constructor");
> 	}
> }
>
> void main()
> {
> 	// always works
> 	auto x = new MyClass("hi");
>
> 	// error, depending on @disable this()
> 	// why won't it match the ctor with default args?
> 	auto y = new MyClass();
> }
> ```

I think you've reached a grey zone related to overload 
resolution. This is worth a bug report. The fix is not 
necessarily to allow that code but maybe to update the specs.

Anyway, good catch I'd say.


More information about the Digitalmars-d-learn mailing list