checked_cast<uint>(SIZE_MAX) => error as expected
checked_cast<int>(SIZE_MAX) => no error?
The problem is that SIZE_MAX successfully round-trips because
static_cast<size_t>(-1) => SIZE_MAX
due to sign extension when promoting the type.
Another case where it doesn't work is casting an integer to an enum. If the integer doesn't fit in the enum type, that's UB. (C++20 changes some cases.)
- relates to
-
JDK-8135181 Re-enable '-Wconversion' for GCC 4.3 and later
-
- Open
-
-
JDK-8358957 [ubsan]: The assert in layout_helper_boolean_diffbit() in klass.hpp needs UB to fail
-
- In Progress
-
-
JDK-8314694 Separate checked_cast from globalDefinitions.hpp
-
- Resolved
-
-
JDK-8374712 AOTMappedHeapWriter::relocate_field_in_buffer should use CompressedOops::narrow_oop_cast
-
- Resolved
-
-
JDK-8331799 ubsan: g1Policy.cpp:1114:33: runtime error: 2.71198e+167 is outside the range of representable values of type 'const unsigned long'
-
- Closed
-
- links to
-
Review
openjdk/jdk/16005