Skip to content

gtask: Use unsigned bit-field struct values to avoid warnings

Marco Trevisan requested to merge 3v1n0/glib:gtask-bitfields-fix into main

In recent Clang we may get a build warning as per:

../gio/gtask.c: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]

../gio/gtask.c:653:27: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
  task->check_cancellable = TRUE;
                          ^ ~~~~
../gio/gtask.c:1237:19: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
  task->completed = TRUE;
                  ^ ~~~~
../gio/gtask.c:1264:25: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
    task->ever_returned = TRUE;
                        ^ ~~~~
../gio/gtask.c:1267:22: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
    task->result_set = TRUE;
                     ^ ~~~~
../gio/gtask.c:1375:25: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
  task->thread_complete = TRUE;
                        ^ ~~~~
../gio/gtask.c:1516:58: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
          task->thread_cancelled = task->thread_complete = TRUE;
                                                         ^ ~~~~
../gio/gtask.c:1538:31: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
    task->blocking_other_task = TRUE;
                              ^ ~~~~
../gio/gtask.c:1617:21: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
  task->synchronous = TRUE;
                    ^ ~~~~
../gio/gtask.c:1630:19: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
  task->completed = TRUE;
                  ^ ~~~~
../gio/gtask.c:1684:23: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion]
      task->had_error = TRUE;
                      ^ ~~~~

This is because we use gboolean (and thus a signed type) for bit-fields. Now, this is not an issue in practice for the way we're using them, but still better to mute such compiler warns in the right way.

Merge request reports