```D
import std.stdio;
struct Foo {
@disable this(this);
int x;
}
void test(Foo[] foos...) {
foreach (ref f; foos) {
writeln(&f, ": ", f.x);
f.x = 0;
}
}
void main()
{
Foo f1 = Foo(1);
Foo f2 = Foo(2);
writeln("f1: ", &f1);
writeln("f2: ", &f2);
test(f1, f2);
writeln("f1: ", f1.x);
writeln("f2: ", f2.x);
}
```
This can compile without any warning or error but at the same time foos aren't passed as a reference.
At least it shouldn't allow to pass the noncopyable variables.
For a record a possible workaround that works:
```D
void test(ARGS...)(ARGS foos)
if (ARGS.length >= 1 && allSameType!ARGS && is(ARGS[0] == Foo))
{ ... }
```
This would rightly complain that Foo is not copyable and with `(ref ARGS foos)` we can also pass foos by reference when needed.
Comment #1 by johan_forsberg_86 — 2022-11-03T22:49:08Z
Side note, if changed to
```d
void test(Foo[] foos)
```
And passed that way, you get the Error: struct `Foo` is not copyable because it has a disabled postblit.
So it seems (potentially) limited to vararg.
Comment #2 by dlang-bot — 2022-11-04T13:40:04Z
@RazvanN7 created dlang/dmd pull request #14616 "Fix Issue 23452 - Noncopyable variable can be silently passed to a function with variadic args" fixing this issue:
- Fix Issue 23452 - Noncopyable variable can be silently passed to a function with variadic args
https://github.com/dlang/dmd/pull/14616
Comment #3 by robert.schadek — 2024-12-13T19:25:24Z