Re: Error on negating unsigned types

2017-07-13 Thread Steven Schveighoffer via Digitalmars-d
On 7/12/17 5:24 PM, Johan Engelen wrote: On Wednesday, 12 July 2017 at 20:12:03 UTC, Steven Schveighoffer wrote: ... Which means this may cause a bunch of nuisance errors. It's a trade-off between nuisance in some cases (the Phobos ones can be solved with val = abs(val), or with static if), a

Re: Error on negating unsigned types

2017-07-12 Thread Walter Bright via Digitalmars-d
On 7/11/2017 12:46 PM, Johan Engelen wrote: So, adding the error may be nice, but it would make generic code a little more verbose. The particular issue you were having appears to be a bug in the compiler (I already filed it as a bug report). Being a bug, we need more evidence that adding an

Re: Error on negating unsigned types

2017-07-12 Thread Johan Engelen via Digitalmars-d
On Wednesday, 12 July 2017 at 20:12:03 UTC, Steven Schveighoffer wrote: ... Which means this may cause a bunch of nuisance errors. It's a trade-off between nuisance in some cases (the Phobos ones can be solved with val = abs(val), or with static if), and possibly catching bugs in other cases.

Re: Error on negating unsigned types

2017-07-12 Thread Steven Schveighoffer via Digitalmars-d
On 7/12/17 11:00 AM, Andrei Alexandrescu wrote: On 07/11/2017 03:46 PM, Johan Engelen wrote: So, adding the error may be nice, but it would make generic code a little more verbose. Ideas? People OK with that? A compelling argument is that the rule exposed two bugs in Phobos. -- Andrei Th

Re: Error on negating unsigned types

2017-07-12 Thread Andrei Alexandrescu via Digitalmars-d
On 07/11/2017 03:46 PM, Johan Engelen wrote: So, adding the error may be nice, but it would make generic code a little more verbose. Ideas? People OK with that? A compelling argument is that the rule exposed two bugs in Phobos. -- Andrei

Re: Error on negating unsigned types

2017-07-11 Thread ketmar via Digitalmars-d
Walter Bright wrote: On 7/11/2017 12:46 PM, Johan Engelen wrote: uint total = 0; void add(int x) { total += x; } ubyte popCount() { return 5; } add(popCount()); add(-popCount()); writeln(total); // <-- what does this print? (behavior is different from C) The behavior should be the same. htt

Re: Error on negating unsigned types

2017-07-11 Thread Walter Bright via Digitalmars-d
On 7/11/2017 12:46 PM, Johan Engelen wrote: uint total = 0; void add(int x) { total += x; } ubyte popCount() { return 5; } add(popCount()); add(-popCount()); writeln(total); // <-- what does this print? (behavior is different from C) The behavior should be the same. https://issues.dlang.org/s

Re: Error on negating unsigned types

2017-07-11 Thread Guillaume Chatelet via Digitalmars-d
On Tuesday, 11 July 2017 at 20:05:43 UTC, Johan Engelen wrote: On Tuesday, 11 July 2017 at 20:02:07 UTC, Johan Engelen wrote: On Tuesday, 11 July 2017 at 19:57:06 UTC, Johan Engelen wrote: On Tuesday, 11 July 2017 at 19:46:00 UTC, Johan Engelen wrote: [...] Also this nice hackery would need

Re: Error on negating unsigned types

2017-07-11 Thread Eyal Lotem via Digitalmars-d
On Tuesday, 11 July 2017 at 19:46:00 UTC, Johan Engelen wrote: The Weka folks would like to see a compile error on negating unsigned types: The error would be great! I've filed a bug yesterday: https://issues.dlang.org/show_bug.cgi?id=17633 In it I asked to change the result type, b

Re: Error on negating unsigned types

2017-07-11 Thread Daniel Kozak via Digitalmars-d
< digitalmars-d@puremagic.com> wrote: > On Tuesday, 11 July 2017 at 19:46:00 UTC, Johan Engelen wrote: > >> The Weka folks would like to see a compile error on negating unsigned >> types: >> > > Also this nice hackery would need a workaround: > ``` >if ((y&(-y))==y) > ``` > > >

Re: Error on negating unsigned types

2017-07-11 Thread Johan Engelen via Digitalmars-d
On Tuesday, 11 July 2017 at 20:02:07 UTC, Johan Engelen wrote: On Tuesday, 11 July 2017 at 19:57:06 UTC, Johan Engelen wrote: On Tuesday, 11 July 2017 at 19:46:00 UTC, Johan Engelen wrote: The Weka folks would like to see a compile error on negating unsigned types: Also this nice hackery

Re: Error on negating unsigned types

2017-07-11 Thread Johan Engelen via Digitalmars-d
On Tuesday, 11 July 2017 at 19:57:06 UTC, Johan Engelen wrote: On Tuesday, 11 July 2017 at 19:46:00 UTC, Johan Engelen wrote: The Weka folks would like to see a compile error on negating unsigned types: Also this nice hackery would need a workaround: ``` if ((y&(-y))==y) ```

Re: Error on negating unsigned types

2017-07-11 Thread Johan Engelen via Digitalmars-d
On Tuesday, 11 July 2017 at 19:46:00 UTC, Johan Engelen wrote: The Weka folks would like to see a compile error on negating unsigned types: Also this nice hackery would need a workaround: ``` if ((y&(-y))==y) ```

Error on negating unsigned types

2017-07-11 Thread Johan Engelen via Digitalmars-d
The Weka folks would like to see a compile error on negating unsigned types: ``` uint total = 0; void add(int x) { total += x; } ubyte popCount() { return 5; } add(popCount()); add(-popCount()); writeln(total); // <-- what does this print? (behavior is different from C) ``` After adding