Compiler bug or incorrect usage for pointer of Struct?

Heromyth bitworld at qq.com
Sun Jan 14 13:24:14 UTC 2018


On Sunday, 14 January 2018 at 08:05:34 UTC, Temtaime wrote:
> On Sunday, 14 January 2018 at 04:02:09 UTC, Heromyth wrote:
>> On Saturday, 13 January 2018 at 14:11:23 UTC, H. S. Teoh wrote:
>>> On Sat, Jan 13, 2018 at 12:22:17PM +0000, Heromyth via 
>>> Digitalmars-d wrote: [...]

>
> https://run.dlang.io/is/RUHtqK
> It's not ok dude
> It runs because you don't use any variable inside the struct 
> and because struct members are simple functions with hidden 
> parameter

Thanks. It's really dangerous to use a pointer to struct!

I have created another test based on your code. See here 
https://run.dlang.io/is/LOeMKG

I add *ref* in the constructor and add a new template fucntion 
writerFor. So, it goes back the scenario in my first post.

Tester tester = new Tester(buildWriter()); 	// can't compile. The 
compiler does the right thing.

Tester tester = writerFor(buildWriter());	// Here is a bug, 
because the compiler takes this!

Am I right?



More information about the Digitalmars-d mailing list