Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/src/dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -1928,7 +1928,7 @@ extern(D) bool arrayExpressionSemantic(
*
* Params:
* sc = the scope where the expression is encountered
* e = the expression the needs to be moved or copied (source)
* e = the expression that needs to be moved or copied (source)
* t = if the struct defines a copy constructor, the type of the destination (can be NULL)
* nrvo = true if the generated copy can be treated as NRVO
* move = true to allow a move constructor to be used, false to prevent infinite recursion
Expand Down Expand Up @@ -4302,6 +4302,7 @@ private bool functionParameters(Loc loc, Scope* sc,
else
a = a.implicitCastTo(sc, tbn);
a = a.addDtorHook(sc);
a = doCopyOrMove(sc, a, null, false);
(*elements)[u] = a;
}
// https://issues.dlang.org/show_bug.cgi?id=14395
Expand Down
33 changes: 33 additions & 0 deletions compiler/test/fail_compilation/fail23452.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// https://issues.dlang.org/show_bug.cgi?id=23452

/*
TEST_OUTPUT:
---
fail_compilation/fail23452.d(24): Error: struct `fail23452.Foo` is not copyable because it has a disabled postblit
fail_compilation/fail23452.d(24): Error: struct `fail23452.Foo` is not copyable because it has a disabled postblit
fail_compilation/fail23452.d(26): Error: copy constructor `fail23452.NoCopy.this` cannot be used because it is annotated with `@disable`
---
*/

struct Foo
{
@disable this(this);
int x;
}

void test(E)(E[] foos...) {}

void main()
{
Foo f1 = Foo(1);
Foo f2 = Foo(2);
test(f1, f2);
NoCopy nc;
test(nc);
}

struct NoCopy
{
@disable this(ref NoCopy);
int x;
}
8 changes: 5 additions & 3 deletions compiler/test/runnable/test19393.d
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,25 @@ struct S

void foo(const(S)[] ar...)
{
assert(result == "A");
/* postblit gets called on this initialization,
* then when the function returns, the destructor
* gets called => result = "AB";
* gets called, appending "B";
*/
auto d = ar[0];
assert(result == "AA");
}

void bar()
{
/* S(null) needs to be destroyed after the function call,
* that means that another `B` is appended => result = "ABB"
* that means that another `B` is appended
*/
foo(S());
}

void main()
{
bar();
assert(result == "ABB");
assert(result == "AABB");
}
Loading