Skip to content

Missing warnings for UB float to unsigned cast #168778

@Alcaro

Description

@Alcaro
// Type your code here, or load an example.
unsigned line() { return -1.0; }
unsigned square() { return static_cast<unsigned>(-1.0); }
unsigned cube() { return (unsigned)-1.0; }
unsigned tesseract() { double num = -1.0; return num; }

Expected: All four compile to a single ret with -O2 (https://godbolt.org/z/h4vfe77qn), so I would quite like to see four warnings.
Actual: Only the first one warns.

edit: added one with static_cast because Someone™ on ms-stl discord doesn't like C casts

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerinvalidResolved as invalid, i.e. not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions