digitalmars.D.learn - How to pass noncopyable variadic arguments with ref?
- tchaloupka (32/32) Oct 20 2022 Hi,
- Imperatorn (2/34) Oct 20 2022 Have you looked at the ast?
- user1234 (3/8) Oct 20 2022 it's clearly a compiler bug to me. Something is not checked when
- user1234 (4/12) Oct 20 2022 however (forgot to say) this form of variadic was proposed for
- ryuukk_ (6/38) Oct 21 2022 void test(Foo..)(Foo foos)
- tchaloupka (4/10) Nov 03 2022 Yeah, I've ended up with this kind of workaround too.
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, ": ", 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); } ``` 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?
Oct 20 2022
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, ": ", 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); } ``` 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?
Oct 20 2022
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.
Oct 20 2022
On Thursday, 20 October 2022 at 16:34:34 UTC, user1234 wrote:On Thursday, 20 October 2022 at 14:03:10 UTC, tchaloupka wrote:however (forgot to say) this form of variadic was proposed for deprecation. So maybe the bug is more an argument to drop them.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.
Oct 20 2022
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, ": ", 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); } ``` 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
Oct 21 2022
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 postblitYeah, I've ended up with this kind of workaround too. Posted a bug report: https://issues.dlang.org/show_bug.cgi?id=23452
Nov 03 2022