Explicit default constructor for structs

Brian Schott briancschott at gmail.com
Wed Apr 9 12:19:55 PDT 2014


On Wednesday, 9 April 2014 at 18:53:20 UTC, Brian Schott wrote:
> On Wednesday, 9 April 2014 at 18:47:41 UTC, Benjamin Thaut 
> wrote:
>> Thats easy to answer. What would it do if you replace the 
>> "struct" with "class" and the "void" with nothing?
>
> This thread is giving me some fun ideas for static analysis 
> rules.

As of a minute ago D-Scanner will warn about the following code:

class TestClass
{
	this() { i = 10; }
	this(int i = 20) { this.i = i; }
	int i;
}

struct Bogus
{
	this(int x = 0) {}
}

test.d(1:7)[warn]: This class has a zero-argument constructor as 
well as a constructor with one default argument. This can be 
confusing
test.d(10:2)[warn]: This struct constructor can never be called 
with its default argument.


More information about the Digitalmars-d mailing list