3 ms·
Not sure if Swift has the mechanisms to do it, but for example, you could wrap your syscalls in something that requires an error to be checked. In C++ it can on
by a_t48 7y ago
Not sure if Swift has the mechanisms to do it, but for example, you could wrap your syscalls in something that requires an error to be checked. In C++ it can only be a runtime check (outside of extensions?). I _think_ Rust might allow a compile time check but I don't remember which mechanism you'd do it from. Don't know about Swift.
Edit: of course you're always allowed to check and discard the error. No language can stop people from purposefully shoot themselves in the foot, but at least safeties can be installed.
- fools 7y agoRust has compile-time warnings for when you don't use the result of a function whose return type is marked as #[must_use]. You can easily silence such a warning by writing `let _ = f(...)`, though, but I don't think that's a bad thing.
- detaro 7y agoC++ has the nodiscard attribute for this now.
- saagarjha 7y agoFunctions in Swift must be annotated to allow discarding their results without a warning.
- cozzyd 7y agoAt least on on my system, ftruncate is annotated with __wur, so a simple -D_FORTIFY_SOURCE would suffice to produce a warning in this case.