Skip to content

Negative literals cast to unsigned integers without a warning. #16313

Closed
@mahkoh

Description

@mahkoh
let i: u8 = -1

Replacing -1 by 256 gives the following warning:

 literal out of range for its type

This could also apply to the code above. Unfortunately even an explicit cast to u8 doesn't remove the second warning.

Note that clang has a related warning:

warning: implicit conversion changes signedness: 'int' to 'unsigned int' [-Wsign-conversion]
        unsigned int i = -1;
                     ~   ^~

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