Skip to content

A comparison operator (< > <= >=) between distinct integral types might hide a bug #5331

@kevinb9n

Description

@kevinb9n

An expression like someInt < someLong is at least "fishy" (no offense to our aquatic friends), because assuming that the wider type actually needs to be wider (can't be safely cast down to the narrower type), then this expression will always have the same result every time it executes. This seems to have some reasonable chance of being not-what-the-user-really-intended.

Example - this loop might never terminate:

long limit = ...
for (int i = 0 ; i < limit ; i++) {
 ...
}

(EDIT: if either operand is a constant expression, this issue doesn't really apply in the same way; we should reason based on its actual value instead of worrying about ranges. Also, this issue doesn't apply in the same when comparing say an int to a double; I was thinking of integral types.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions