Index: cfe/trunk/lib/Sema/SemaChecking.cpp =================================================================== --- cfe/trunk/lib/Sema/SemaChecking.cpp +++ cfe/trunk/lib/Sema/SemaChecking.cpp @@ -8006,11 +8006,10 @@ unsigned OriginalWidth = Value.getBitWidth(); unsigned FieldWidth = Bitfield->getBitWidthValue(S.Context); - if (Value.isSigned() && Value.isNegative()) + if (!Value.isSigned() || Value.isNegative()) if (UnaryOperator *UO = dyn_cast(OriginalInit)) - if (UO->getOpcode() == UO_Minus) - if (isa(UO->getSubExpr())) - OriginalWidth = Value.getMinSignedBits(); + if (UO->getOpcode() == UO_Minus || UO->getOpcode() == UO_Not) + OriginalWidth = Value.getMinSignedBits(); if (OriginalWidth <= FieldWidth) return false; Index: cfe/trunk/test/Sema/constant-conversion.c =================================================================== --- cfe/trunk/test/Sema/constant-conversion.c +++ cfe/trunk/test/Sema/constant-conversion.c @@ -69,7 +69,8 @@ unsigned int reserved:28; } f; - f.twoBits1 = ~1; // expected-warning {{implicit truncation from 'int' to bitfield changes value from -2 to 2}} + f.twoBits1 = ~0; // no-warning + f.twoBits1 = ~1; // no-warning f.twoBits2 = ~2; // expected-warning {{implicit truncation from 'int' to bitfield changes value from -3 to 1}} f.twoBits1 &= ~1; // no-warning f.twoBits2 &= ~2; // no-warning @@ -114,6 +115,8 @@ char array_init[] = { 255, 127, 128, 129, 0 }; } +#define A 1 + void test10() { struct S { unsigned a : 4; @@ -121,7 +124,10 @@ s.a = -1; s.a = 15; s.a = -8; + s.a = ~0; + s.a = ~0U; + s.a = ~(1<