RFR: 8312121: Fix -Wconversion warnings in tribool.hpp

Coleen Phillimore coleenp at openjdk.org
Mon Jul 24 12:35:41 UTC 2023


On Mon, 24 Jul 2023 12:12:15 GMT, Coleen Phillimore <coleenp at openjdk.org> wrote:

>> It does seem strange that this code is using a bit-field, but still using & | and shift.  Why not represent the high and low bit with two separate bit-fields of width 1?
>
> I tried to change the class to be int value : 1, init: 1;  the changes got a bit ugly when fixing the TriBoolArray functions.

expr & 3 is the wrong expression.  This wants to set the 'not-default' bit, not and in the 'not-default' bit if it's set in the value.  Thankfully, tribool has a gtest.

tribool.hpp:43:43: warning: conversion from 'unsigned int' to 'unsigned char:2' may change value [-Wconversion]
   43 |   TriBool(bool value) : _value((u1)value  | (u1)2) {
      |                                ~~~~~~~~~~~^~~~~~~

Casting 2 to u1 doesn't work because | still promotes to unsigned int.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/14892#discussion_r1272200460


More information about the hotspot-dev mailing list