Consider:
import std.stdio, std.typecons;
struct S
{
this(this) { writeln("making a copy"); }
}
void main() {
Tuple!(S, int) x;
auto p1 = &(x.init);
//auto p2 = &(Tuple!(S, int).init);
}
The program as is calls the copy constructor of S twice. It should call none (for at least two reasons: effciency and the fact that some types want to disable copying).
Furthermore, uncommenting the last line in main yields a compile-time error. It should compile and run (again without invoking the copy constructor).
Comment #1 by k.hara.pg — 2012-05-30T18:55:00Z
(In reply to comment #0)
> Consider:
>
> import std.stdio, std.typecons;
>
> struct S
> {
> this(this) { writeln("making a copy"); }
> }
>
> void main() {
> Tuple!(S, int) x;
> auto p1 = &(x.init);
> //auto p2 = &(Tuple!(S, int).init);
> }
>
> The program as is calls the copy constructor of S twice. It should call none
> (for at least two reasons: effciency and the fact that some types want to
> disable copying).
>
> Furthermore, uncommenting the last line in main yields a compile-time error. It
> should compile and run (again without invoking the copy constructor).
From 2.059, T.init always returns rvalue even if T is struct.
So getting address of init property by & operator is rejected in compile.
I think this issue should be closed with the status "resolved invalid".
Comment #2 by k.hara.pg — 2013-05-26T23:13:10Z
(In reply to comment #1)
> I think this issue should be closed with the status "resolved invalid".
The explained behavior was actually a bug, so it didn't invalid.
I'll mark this "fixed".