Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8312190

Fix c++11-narrowing warnings in hotspot code

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 22
    • 22
    • hotspot
    • b07
    • windows

      Happens only when compiling with clang for Windows.

      The following warnings were observed when compiling hotspot code:

      src\hotspot\share\classfile\verificationType.cpp(165,10): error:
            case value evaluates to -65535, which cannot be narrowed to type
            'uintptr_t' (aka 'unsigned long long') [-Wc++11-narrowing]
          case Bogus: st->print("top"); break;
               ^

      src\hotspot\share\utilities\vmError.cpp(812,12): error: case value evaluates to -536870911, which cannot be narrowed to type 'unsigned int' [-Wc++11-narrowing]
            case OOM_MALLOC_ERROR:
                 ^
      src\hotspot\share\utilities\vmError.cpp(813,12): error: case value evaluates to -536870910, which cannot be narrowed to type 'unsigned int' [-Wc++11-narrowing]
            case OOM_MMAP_ERROR:
                 ^
      src\hotspot\share\utilities\vmError.cpp(814,12): error: case value evaluates to -536870909, which cannot be narrowed to type 'unsigned int' [-Wc++11-narrowing]
            case OOM_MPROTECT_ERROR:
                 ^
      src\hotspot\share\utilities\vmError.cpp(841,12): error: case value evaluates to -536870912, which cannot be narrowed to type 'unsigned int' [-Wc++11-narrowing]
            case INTERNAL_ERROR:
                 ^

      Note: Microsoft compiler uses int for enums, even if the values specified are too large to fit in an int. VS2022 added a new parameter -Zc:enumTypes [1] that makes it assign other types as required by the standard

      [1] https://learn.microsoft.com/en-us/cpp/build/reference/zc-enumtypes?view=msvc-170

      Clang emulates MSVC's behavior and uses int for the enums. Then it produces the warnings described above.

      The warnings can be easily fixed by specifying the right type for enums.

            djelinski Daniel Jelinski
            djelinski Daniel Jelinski
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: