Safety

No Implicit Downcasts

Standard conversions only apply when no information is lost.

Not OK or OK is

Signed Size

Using signed Int as size

Range & Validation Checks

The low hanging fruit would be to enable by default, also in release builds (not only in debug):

This should fix the majority of C/C++ security issues.
To achieve maximum performance in all cases, there could be a third build configuration for even faster, but potentially unsafe builds.

So we would have:

Initialization

Safe / Unsafe

safe code blocks as default, unsafe as escape.
Mainly to guide developers:

Not allowed in safe code:

Still allowed/undetected in unsafe code:

unsafe code is necessary to implement certain abstractions (like container classes):

operator[Int i] -> T& {
  if CHECK_BOUNDS and (i < 0 or i >= size) {
      terminate()
  }
  unsafe {
      return data[i]
  }
}

A function with unsafe code does not necessarily have to be marked as unsafe itself. unsafe is a marker for those parts (subfunctions or code blocks) that are not safe (i.e. dangerous) and need to be checked carefully.

Functions containing unsafe code enclosed in an unsafe block do not have to be marked with unsafe themselves. Only functions containing unsafe code not enclosed in an unsafe block have to be marked with unsafe themselves. Unsafe is transitive (from an unsafe inner function to the outer function), but limited to the scope of unsafe blocks.

Int with Overflow Check

cilia::safe::Int is like cilia::Int, but with overflow check for all operations, may throw OverflowException (or abort the program).

Generally considered to be too costly for “normal” integers, even in languages that are otherwise considered as “safe”.

Not like Rust

No further safety features planned beyond C++: