C++ float-to-int conversion can be undefined behavior
1–10 of 70 posts
Re: C++ float-to-int conversion can be undefined behavior
#2Re: C++ float-to-int conversion can be undefined behavior
#3Re: C++ float-to-int conversion can be undefined behavior
#4Re: C++ float-to-int conversion can be undefined behavior
#5> Regarding the use of UB internally: It's okay and if anyone is worried about it the use of UB is benign on the platforms we target (e.g., they don't involve hitting any hardware trap representations for these types)
Isn't the outcome of the UB (ie. whether it will "rm -rf /" or something else) dependent on both the target and the compiler? And the compiler (or future compiler) could plausibly make the assumption that the narrowing to an unrepresentable value will never occur and change behaviour because of it?
Re: C++ float-to-int conversion can be undefined behavior
#6Re: C++ float-to-int conversion can be undefined behavior
#7Herb Sutter's comment on why it's ok is confusing to me: > Regarding the use of UB internally: It's okay and if anyone is worried about it the use of UB is benign on the platforms we target (e.g., they don't involve hitting any hardware trap representations for these types) Isn't the outcome of the UB (ie. whether it will "rm -rf /" or something else) dependent on both the target and the compiler? And the compiler (o…
Meaning MSVC is aware of these cases, so the compiler has special cases for it.
Re: C++ float-to-int conversion can be undefined behavior
#8Re: C++ float-to-int conversion can be undefined behavior
#9How could it be defined behaviour, when the result is different on ARM and x86?
Re: C++ float-to-int conversion can be undefined behavior
#10Herb Sutter's comment on why it's ok is confusing to me: > Regarding the use of UB internally: It's okay and if anyone is worried about it the use of UB is benign on the platforms we target (e.g., they don't involve hitting any hardware trap representations for these types) Isn't the outcome of the UB (ie. whether it will "rm -rf /" or something else) dependent on both the target and the compiler? And the compiler (o…
GCC 12, 13, 14
XCode 14.3.1, 15.4
Clang 16, 17, 18
Visual Studio with MSVC VS2019, VS2022
Visual Studio with LLVM VS2019, VS2022