Make undefined behaviour a compiler error when running in pure Cpp2 mode where possible. #1089
LouChiSoft
started this conversation in
Suggestions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I couldn't find anything related to this when I searched the discussions and the repo itself so I figured I would make the suggestion. If it has been discussed please feel free to point me in the right direction.
Will your feature suggestion eliminate X% of security vulnerabilities of a given kind in current C++ code: Given the nature of the suggestion, maybe.
Will your feature suggestion automate or eliminate X% of current C++ guidance literature: I think so, basically anything to do with undefined behaviour could be replaced with "If it's undefined, it's an error"
This is somewhat of a gotcha for early developers in my opinion, you do a thing, that thing compiles and it works as you intended. But then you give that code to some one else, they build and run it and it doesn't work. A typical "but it works on my PC" scenario. Given the nature of undefined behaviour is that is has no definition and it's up to the compilers discrection what actually happens I would argue that it's an error. Just currently an error at runtime rather than compile time.
By making any compile time assertable examples of UB a compile time error you cut out an entire class of potential bugs from ever happening in the first place. I won't assume that all undefined behaviours can be asserted at compile time, accessing outside of bounds is technically UB and for dynamicly sized containers this could be difficult/impossible to assert at compile time, but removing as many as possible also removes a lot of potholes that especially newer developers might fall into, I also realise that this could (and likely would) cause compile time errors for currently existing Cpp1 code, and while one could argue that that would actually be a good thing that forces said code to be updated, in the spirit of not breaking currently existing code making it a pure Cpp2 code feature would retain backward compatability.
Maybe this is something that can be rolled into the unsafe code practices that Herb has written about in the wiki section and have a
[[suppress ignore-undefined-behaviour]]
flag that the user has to opt into to get the same behaviour they would have been allowed to have in Cpp1Beta Was this translation helpful? Give feedback.
All reactions