]> granicus.if.org Git - clang/commitdiff
Change the check for constant-conversion with width-1 bitfields so it doesn't suppres...
authorEli Friedman <eli.friedman@gmail.com>
Thu, 2 Feb 2012 00:40:20 +0000 (00:40 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Thu, 2 Feb 2012 00:40:20 +0000 (00:40 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149572 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaChecking.cpp
test/Sema/constant-conversion.c

index ee044630373973a867cea298a635cc65d961b072..9dbee1b2b3c690772c150ee886374e7cccba73a4 100644 (file)
@@ -3758,8 +3758,8 @@ static bool AnalyzeBitFieldAssignment(Sema &S, FieldDecl *Bitfield, Expr *Init,
     return false;
 
   // Special-case bitfields of width 1: booleans are naturally 0/1, and
-  // therefore don't strictly fit into a bitfield of width 1.
-  if (FieldWidth == 1 && Value.getBoolValue() == TruncatedValue.getBoolValue())
+  // therefore don't strictly fit into a signed bitfield of width 1.
+  if (FieldWidth == 1 && Value == 1)
     return false;
 
   std::string PrettyValue = Value.toString(10);
index e3097f8be30e85862a8d1c1b9399a6b7e6b971a4..137633396712763973aedcdb60b5fb63a9b95225 100644 (file)
@@ -74,3 +74,9 @@ void test7() {
        f.twoBits1 &= ~1; // no-warning
        f.twoBits2 &= ~2; // no-warning
 }
+
+void test8() {
+  enum E { A, B, C };
+  struct { enum E x : 1; } f;
+  f.x = C; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 2 to 0}}
+}