Re: How to pass noncopyable variadic arguments with ref?
On Friday, 21 October 2022 at 12:05:28 UTC, ryuukk_ wrote: On Thursday, 20 October 2022 at 14:03:10 UTC, tchaloupka wrote: void test(Foo..)(Foo foos) I don't know if that's the 1:1 alternative, but that doesn't compile onlineapp.d(23): Error: struct `onlineapp.Foo` is not copyable because it has a disabled postblit Yeah, I've ended up with this kind of workaround too. Posted a bug report: https://issues.dlang.org/show_bug.cgi?id=23452
Re: How to pass noncopyable variadic arguments with ref?
On Thursday, 20 October 2022 at 14:03:10 UTC, tchaloupka wrote: Hi, I've found strange behavior where: ```D import std.stdio; struct Foo { @disable this(this); int x; } void test(Foo[] foos...) { foreach (ref f; foos) { writeln(, ": ", f.x); f.x = 0; } } void main() { Foo f1 = Foo(1); Foo f2 = Foo(2); writeln("f1: ", ); writeln("f2: ", ); test(f1, f2); writeln("f1: ", f1.x); writeln("f2: ", f2.x); } ``` Compiles fine (no error on passing noncopyable arguments to the function), but there are other objects passed to the function as they aren't cleared out in the caller scope. Shouldn't it at least protest that objects can't be passed to the function as they aren't copyable? void test(Foo..)(Foo foos) I don't know if that's the 1:1 alternative, but that doesn't compile onlineapp.d(23): Error: struct `onlineapp.Foo` is not copyable because it has a disabled postblit
Re: How to pass noncopyable variadic arguments with ref?
On Thursday, 20 October 2022 at 16:34:34 UTC, user1234 wrote: On Thursday, 20 October 2022 at 14:03:10 UTC, tchaloupka wrote: Hi, I've found strange behavior where: [...] Shouldn't it at least protest that objects can't be passed to the function as they aren't copyable? it's clearly a compiler bug to me. Something is not checked when the call is verified. however (forgot to say) this form of variadic was proposed for deprecation. So maybe the bug is more an argument to drop them.
Re: How to pass noncopyable variadic arguments with ref?
On Thursday, 20 October 2022 at 14:03:10 UTC, tchaloupka wrote: Hi, I've found strange behavior where: [...] Shouldn't it at least protest that objects can't be passed to the function as they aren't copyable? it's clearly a compiler bug to me. Something is not checked when the call is verified.
Re: How to pass noncopyable variadic arguments with ref?
On Thursday, 20 October 2022 at 14:03:10 UTC, tchaloupka wrote: Hi, I've found strange behavior where: ```D import std.stdio; struct Foo { @disable this(this); int x; } void test(Foo[] foos...) { foreach (ref f; foos) { writeln(, ": ", f.x); f.x = 0; } } void main() { Foo f1 = Foo(1); Foo f2 = Foo(2); writeln("f1: ", ); writeln("f2: ", ); test(f1, f2); writeln("f1: ", f1.x); writeln("f2: ", f2.x); } ``` Compiles fine (no error on passing noncopyable arguments to the function), but there are other objects passed to the function as they aren't cleared out in the caller scope. Shouldn't it at least protest that objects can't be passed to the function as they aren't copyable? Have you looked at the ast?
How to pass noncopyable variadic arguments with ref?
Hi, I've found strange behavior where: ```D import std.stdio; struct Foo { @disable this(this); int x; } void test(Foo[] foos...) { foreach (ref f; foos) { writeln(, ": ", f.x); f.x = 0; } } void main() { Foo f1 = Foo(1); Foo f2 = Foo(2); writeln("f1: ", ); writeln("f2: ", ); test(f1, f2); writeln("f1: ", f1.x); writeln("f2: ", f2.x); } ``` Compiles fine (no error on passing noncopyable arguments to the function), but there are other objects passed to the function as they aren't cleared out in the caller scope. Shouldn't it at least protest that objects can't be passed to the function as they aren't copyable?