Skip to content

Division by zero is undefined behavior #11059

@iacore

Description

@iacore

The official language website claims that V has "no undefined behavior". However, division by zero is undefined with C as backend. I think this makes division by zero undefined as well.

Also, overflow/underflow is undefined as well.

OS: linux, "Arch Linux"
CC version: cc (GCC) 11.1.0
V full version: V 0.2.2 69f31d8

What did you do?
Run the following program with v run test.v

fn main() {
    a := 0
    println(1 / a)
}

What did you expect to see?
Make x / 0 a defined value, e.g. 0, and allow or block after it.
Or, like in Pony, add operators like /? that propagates the error.

What did you see instead?
Runtime error in debug mode.

SIGILL in release mode.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugThis tag is applied to issues which reports bugs.Status: Won't FixThis issue would not be worked on.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions