https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83151
Bug ID: 83151 Summary: Explicit unsigned bitfields are treated as signed ones Product: gcc Version: 7.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: lh_mouse at 126 dot com Target Milestone: --- Minimal testcase: ```c struct foo { unsigned bf : 6; }; unsigned get(const struct foo *ptr){ return ~ptr->bf; } ``` ``` E:\Desktop>gcc -c test.c -Wall -Wextra -Wsign-conversion -Werror test.c: In function 'get': test.c:6:10: error: conversion to 'unsigned int' from 'int' may change the sign of the result [-Werror=sign-conversion] return ~ptr->bf; ^~~~~~~~ cc1.exe: all warnings being treated as errors ``` GCC manual says > -fsigned-bitfields > -funsigned-bitfields > -fno-signed-bitfields > -fno-unsigned-bitfields > These options control whether a bit-feld is signed or unsigned, when the > declaration does not use either signed or unsigned. By default, such a > bit-feld is > signed, because this is consistent: the basic integer types such as int are > signed > types. but it looks certainly incorrect if an explicit `unsigned` is specified.