What do those languages return when you calculate MAX_INT + 1?
let a = Int.max + 1
Produces a compile error as the overflow is within Swift's conception of a "literal expression".If we step out to a case where the overflow is not trivially a literal expression:
func foo(a: Int) -> Int {
return Int.max + a
}
foo(1)
This causes a runtime assertion failure in optimized or unoptimized builds.There is a (rarely-used) "Ounchecked" optimization level for which this program produces UB.
let x = std::u32::MAX + 1;
This line will generate a warning upon build, and in a debug build, will panic. In a release build, it will overflow.