r/cpp • u/pavel_v • Jul 29 '26
C++26: Reducing undefined behaviour
https://www.sandordargo.com/blog/2026/07/29/cpp26-reduces-undefined-behaviour
89
Upvotes
r/cpp • u/pavel_v • Jul 29 '26
View all comments
Show parent comment
4
u/jk-jeon Jul 30 '26
Maybe it'd be slightly better to also check if the base of those types is 2. Non-binary
float/doubleis also extremely rare. I'm not even sure such a platform exists.Still, I'm not quite sure exactly what guarantee
is_iec559provides. I remember I conlcuded it's very vague in the standard (not sure if I recall correctly) like "it'strueif the type is IEEE-754 compliant" and no more explanation, or something like that. Technically, that means -ffast-math must make itfalse. But does it? And AFAIK many platforms that claim to be IEEE-754 compliant actually only partially support floating-point exceptions, or maybe only part of the required math functions, and things like that.One aspect that particularly mattered for me was: if
is_iec559istrue,baseis 2, andsizeofis N, can I assume the type precisely corresponds to IEEE-754 binary(N *CHAR_BIT)? Or does the standard doesn't preclude possibilities like the type contains unused high-bits so that it's actually binaryM for some M smaller than N timesCHAR_BIT? I still don't know the answer.