Issue 53107
Summary Clang doesn't warn about out-of-range float to int cast
Labels clang:frontend
Assignees
Reporter zmodem
    Consider: (https://godbolt.org/z/K3aWWK8a4)

```
unsigned f() {
    return (unsigned)4294967808.;
}
```

Since the value is out of range, the behaviour is undefined and LLVM will optimize the result to undef, which is probably not what the developer wanted.

Clang doesn't warn there. It would warn however, if the conversion were implicit:

```
unsigned g() {
    return 4294967808.;
}

<source>:6:12: warning: implicit conversion of out of range value from 'double' to 'unsigned int' is undefined [-Wliteral-conversion]
    return 4294967808.;
    ~~~~~~ ^~~~~~~~~~~
```

Perhaps it would make sense to warn in both cases?
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to