www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - typedef behavior with disable this()

reply Alex <sascha.orlov gmail.com> writes:
Do I overlook something?

/// --- code --- ///

import std.typecons;

void main(){}

static assert(!__traits( compiles, E()));
static assert(!__traits( compiles, MyE())); // line 6

struct E
{
	size_t dummy;
	 disable this();
	this(size_t val) { dummy = val; }
}

alias MyE = Typedef!E;

/// --- code ends --- ///

While line 5 does not compile as expected, due to disabled 
default constructor, the Typedef'd type does. Why?
Feb 10 2018
parent reply Simen =?UTF-8?B?S2rDpnLDpXM=?= <simen.kjaras gmail.com> writes:
On Saturday, 10 February 2018 at 13:18:28 UTC, Alex wrote:
 Do I overlook something?

 /// --- code --- ///

 import std.typecons;

 void main(){}

 static assert(!__traits( compiles, E()));
 static assert(!__traits( compiles, MyE())); // line 6

 struct E
 {
 	size_t dummy;
 	 disable this();
 	this(size_t val) { dummy = val; }
 }

 alias MyE = Typedef!E;

 /// --- code ends --- ///

 While line 5 does not compile as expected, due to disabled 
 default constructor, the Typedef'd type does. Why?
Typedef explicitly initializes the wrapped value to T.init, thus circumventing the disabled default constructor. Filed a bug: https://issues.dlang.org/show_bug.cgi?id=18415 -- Simen
Feb 10 2018
parent Alex <sascha.orlov gmail.com> writes:
On Sunday, 11 February 2018 at 00:54:07 UTC, Simen Kjærås wrote:
 Typedef explicitly initializes the wrapped value to T.init, 
 thus circumventing the disabled default constructor. Filed a 
 bug:

 https://issues.dlang.org/show_bug.cgi?id=18415

 --
   Simen
Thanks!
Feb 10 2018