Skip to content

Commit

Permalink
fix Issue 15045 - hasElaborateCopyConstructor is true for struct with…
Browse files Browse the repository at this point in the history
… opDispatch

Stop forwarding these special aggregate members through
opDispatch, alias this, or opDot.

 __ctor (Id.ctor)
 __dtor (Id.dtor)
 __xdtor (Id.__xdtor)
 __postblit (Id.postblit)
 __xpostblit (Id.__xpostblit)
  • Loading branch information
9rnsr committed Sep 15, 2015
1 parent 57c510d commit 38ede74
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/mtype.d
Original file line number Diff line number Diff line change
Expand Up @@ -2589,7 +2589,13 @@ public:
ident != Id._init &&
ident != Id._mangleof &&
ident != Id.stringof &&
ident != Id.offsetof)
ident != Id.offsetof &&
// Bugzilla 15045: Don't forward special built-in member functions.
ident != Id.ctor &&
ident != Id.dtor &&
ident != Id.__xdtor &&
ident != Id.postblit &&
ident != Id.__xpostblit)
{
/* Look for overloaded opDot() to see if we should forward request
* to it.
Expand Down
59 changes: 59 additions & 0 deletions test/runnable/xtest46.d
Original file line number Diff line number Diff line change
Expand Up @@ -7584,6 +7584,65 @@ void test14853()
auto b1 = new Queue14853!uint;
}

/********************************************************/
// 15045

void test15045()
{
void testName(T, bool r, string name)()
{
T t;

static assert(r == is(typeof(mixin("T."~name))));
static assert(r == is(typeof(mixin("t."~name))));
static assert(r == __traits(compiles, mixin("T."~name)));
static assert(r == __traits(compiles, mixin("t."~name)));
static assert(r == mixin("__traits(compiles, T."~name~")"));
static assert(r == mixin("__traits(compiles, t."~name~")"));

static assert(r == __traits(hasMember, T, name) );
static assert(r == __traits(hasMember, t, name) );
static assert(r == __traits(compiles, __traits(getMember, T, name) ));
static assert(r == __traits(compiles, __traits(getMember, t, name) ));
static assert(r == __traits(compiles, __traits(getOverloads, T, name) ));
static assert(r == __traits(compiles, __traits(getOverloads, t, name) ));
}
void test(T, bool r)()
{
testName!(T, r, "__ctor")();
testName!(T, r, "__dtor")();
testName!(T, r, "__xdtor")();
testName!(T, r, "__postblit")();
testName!(T, r, "__xpostblit")();
}

static struct X
{
this(int) {}
this(this) {}
~this() {}
}

static struct S1
{
auto opDispatch(string name, A...)(A args) { }
}
static struct S2
{
X get() { return X(); };
alias get this;
}
static struct S3
{
X opDot() { return X(); };
}

test!(X, true)();
test!(S1, false)();
test!(S2, false)();
test!(S3, false)();
}

/***************************************************/

int main()
Expand Down

0 comments on commit 38ede74

Please sign in to comment.