4 ms·
> There are some nuance around this Sorry, no. There is no nuance around this. It should 100% be an error by default. Same with case fall through. > Recommend
by IshKebab 3y ago
> There are some nuance around this
Sorry, no. There is no nuance around this. It should 100% be an error by default. Same with case fall through.
> Recommend using fixed width integer types instead?
Well yes, in a perfect world they would just remove non-fixed sizes from the language. But that's never going to happen. As an intermediate step they can at least specify the sized of types that are de facto fixed.
> Anyway, aclang-tidy check is enough to enforce this.
Sigh. Well it's good that I don't have to deal with this attitude in Rust at least!
- SubjectToChange 3y agoSorry, no. There is no nuance around this. It should 100% be an error by default. It’s undefined behavior and there are justifiable reasons for being so. Requiring otherwise implies that implementations must exhaustively check every code path in a function. Such an analysis is extremely expensive, and even practically impossible for sufficiently complicated code, it also would need to work across translation units, e.g. akin to whole program optimization. Not to mention cases like linking against a binary library in which the compiler has nothing to analyze at all, or when a functionally impossible non-return path is found but the compiler can not prove to itself that it’s unreachable. Ultimately there are situations in which non-void functions do not have a return value. Moreover, it is certain that a non-trivial amount of code is relying on such behavior. Therefore is unreasonable to make implementations non-conformant and it’s impossible to decide what a reasonable behavior should be otherwise, hence the behavior being undefined. As an intermediate step they can at least specify the sized of types that are de facto fixed. Why hurt non-standard platforms and encourage the use of poorly named integer types? Anyone who cares about this is already using fixed width types. Sigh. Well it's good that I don't have to deal with this attitude in Rust at least! Oh, and Rust doesn’t recommend using linting or code formatting tools like clippy or rustfmt? By all means, use Rust if it’s an option for your needs. C++ is a very old language with all sorts of compromises.