diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -13067,11 +13067,6 @@ if (llvm::APSInt::isSameValue(Value, TruncatedValue)) return false; - // Special-case bitfields of width 1: booleans are naturally 0/1, and - // therefore don't strictly fit into a signed bitfield of width 1. - if (FieldWidth == 1 && Value == 1) - return false; - std::string PrettyValue = toString(Value, 10); std::string PrettyTrunc = toString(TruncatedValue, 10); diff --git a/clang/test/Sema/constant-conversion.c b/clang/test/Sema/constant-conversion.c --- a/clang/test/Sema/constant-conversion.c +++ b/clang/test/Sema/constant-conversion.c @@ -15,8 +15,16 @@ } void test(void) { - struct { int bit : 1; } a; - a.bit = 1; // shouldn't warn + struct S { + signed char c : 1; // the only valid values are 0 and -1 + } s; + + s.c = -3; // expected-warning {{implicit truncation from 'int' to bit-field changes value from -3 to -1}} + s.c = -2; // expected-warning {{implicit truncation from 'int' to bit-field changes value from -2 to 0}} + s.c = -1; // no-warning + s.c = 0; // no-warning + s.c = 1; // expected-warning {{implicit truncation from 'int' to bit-field changes value from 1 to -1}} + s.c = 2; // expected-warning {{implicit truncation from 'int' to bit-field changes value from 2 to 0}} } enum Test2 { K_zero, K_one };