digitalmars.D.learn - Compiler switch for integer comparison/promotion to catch a simple
- frame (8/8) May 28 2022 Is there a compiler switch to catch this kind of error?
- matheus (9/18) May 29 2022 Well I don't know about this, but of course I think (That if not)
- bauss (2/11) May 30 2022 Good luck convincing Walter that this is a mistake :)
- frame (11/12) May 30 2022 Well, I'm not talking about this is a mistake, just a C-thing I
- matheus (7/8) May 30 2022 I don't think this is a matter of convincing or changing the
- Dom Disc (9/18) May 30 2022 We have a solution for this problem in bugzilla:
Is there a compiler switch to catch this kind of error? ```d ulong v = 1; writeln(v > -1); ``` IMHO the compiler should bail a warning if it sees a logic comparison between signed and unsigned / different integer sizes. There is 50% chance that a implicit conversion was not intended.
May 28 2022
On Sunday, 29 May 2022 at 01:35:23 UTC, frame wrote:Is there a compiler switch to catch this kind of error? ```d ulong v = 1; writeln(v > -1); ``` IMHO the compiler should bail a warning if it sees a logic comparison between signed and unsigned / different integer sizes. There is 50% chance that a implicit conversion was not intended.Well I don't know about this, but of course I think (That if not) we should have at least a flag like we have with GCC (-Wextra). Searching about I found in this topic: https://forum.dlang.org/post/hhpacodmcibejatqzdfg forum.dlang.org "Good luck adding a warning into DMD. After years there still isn't a warning for unsigned/signed comparisons." This is from 2017, so let's wait for experienced weighting in. Matheus.
May 29 2022
On Sunday, 29 May 2022 at 01:35:23 UTC, frame wrote:Is there a compiler switch to catch this kind of error? ```d ulong v = 1; writeln(v > -1); ``` IMHO the compiler should bail a warning if it sees a logic comparison between signed and unsigned / different integer sizes. There is 50% chance that a implicit conversion was not intended.Good luck convincing Walter that this is a mistake :)
May 30 2022
On Monday, 30 May 2022 at 13:15:12 UTC, bauss wrote:Good luck convincing Walter that this is a mistake :)Well, I'm not talking about this is a mistake, just a C-thing I think. I wouldn't even ask him about that since it's in the spec. If I could I would just clone a DMD build, disable output of the binary and just add flags to analyze this and other things to check wanted by the community. Just a tool to check for additional bugs running before release - that of course would produce also false positives and should not be in the official compiler. But I'm far too unexperienced to understand the compiler and implement this - I wonder if anyone else ever had this idea?
May 30 2022
On Monday, 30 May 2022 at 13:15:12 UTC, bauss wrote:Good luck convincing Walter that this is a mistake :)I don't think this is a matter of convincing or changing the behavior, I think that a flag for this case (If not exist) should be added as a warning. A language where some people use to spread the phrase "D as better C" should at least have this as flag/warning too. Matheus.
May 30 2022
On Sunday, 29 May 2022 at 01:35:23 UTC, frame wrote:Is there a compiler switch to catch this kind of error? ```d ulong v = 1; writeln(v > -1); ``` IMHO the compiler should bail a warning if it sees a logic comparison between signed and unsigned / different integer sizes. There is 50% chance that a implicit conversion was not intended.We have a solution for this problem in bugzilla: https://issues.dlang.org/show_bug.cgi?id=259 This would allow for the above compare to simply work with all integer types signed or unsigned and produce always the correct result. It was rejected because it would break old code that rely on this misbehaviour (and even worse: the behaviour would be different from what C does, oh my god!!)
May 30 2022