diff options
Diffstat (limited to 'test/Sema/constant-conversion.c')
-rw-r--r-- | test/Sema/constant-conversion.c | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/test/Sema/constant-conversion.c b/test/Sema/constant-conversion.c index 203e7373897c..bf8221089d8c 100644 --- a/test/Sema/constant-conversion.c +++ b/test/Sema/constant-conversion.c @@ -11,7 +11,7 @@ void test_6792488(void) { void test_7809123(void) { struct { int i5 : 5; } a; - a.i5 = 36; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 36 to 4}} + a.i5 = 36; // expected-warning {{implicit truncation from 'int' to bit-field changes value from 36 to 4}} } void test() { @@ -31,11 +31,11 @@ void test3() { int bar : 2; }; - struct A a = { 0, 10 }; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 10 to -2}} - struct A b[] = { 0, 10, 0, 0 }; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 10 to -2}} - struct A c[] = {{10, 0}}; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 10 to 2}} - struct A d = (struct A) { 10, 0 }; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 10 to 2}} - struct A e = { .foo = 10 }; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 10 to 2}} + struct A a = { 0, 10 }; // expected-warning {{implicit truncation from 'int' to bit-field changes value from 10 to -2}} + struct A b[] = { 0, 10, 0, 0 }; // expected-warning {{implicit truncation from 'int' to bit-field changes value from 10 to -2}} + struct A c[] = {{10, 0}}; // expected-warning {{implicit truncation from 'int' to bit-field changes value from 10 to 2}} + struct A d = (struct A) { 10, 0 }; // expected-warning {{implicit truncation from 'int' to bit-field changes value from 10 to 2}} + struct A e = { .foo = 10 }; // expected-warning {{implicit truncation from 'int' to bit-field changes value from 10 to 2}} } void test4() { @@ -43,7 +43,7 @@ void test4() { char c : 2; } a; - a.c = 0x101; // expected-warning {{implicit truncation from 'int' to bitfield changes value from 257 to 1}} + a.c = 0x101; // expected-warning {{implicit truncation from 'int' to bit-field changes value from 257 to 1}} } void test5() { @@ -52,7 +52,7 @@ void test5() { } a; // Don't warn about this implicit conversion to bool, or at least - // don't warn about it just because it's a bitfield. + // don't warn about it just because it's a bit-field. a.b = 100; } @@ -69,8 +69,9 @@ void test7() { unsigned int reserved:28; } f; - f.twoBits1 = ~1; // expected-warning {{implicit truncation from 'int' to bitfield changes value from -2 to 2}} - f.twoBits2 = ~2; // expected-warning {{implicit truncation from 'int' to bitfield changes value from -3 to 1}} + f.twoBits1 = ~0; // no-warning + f.twoBits1 = ~1; // no-warning + f.twoBits2 = ~2; // expected-warning {{implicit truncation from 'int' to bit-field changes value from -3 to 1}} f.twoBits1 &= ~1; // no-warning f.twoBits2 &= ~2; // no-warning } @@ -78,7 +79,7 @@ void test7() { 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}} + f.x = C; // expected-warning {{implicit truncation from 'int' to bit-field changes value from 2 to 0}} } void test9() { @@ -114,6 +115,8 @@ void test9() { char array_init[] = { 255, 127, 128, 129, 0 }; } +#define A 1 + void test10() { struct S { unsigned a : 4; @@ -121,7 +124,10 @@ void test10() { s.a = -1; s.a = 15; s.a = -8; + s.a = ~0; + s.a = ~0U; + s.a = ~(1<<A); - s.a = -9; // expected-warning{{implicit truncation from 'int' to bitfield changes value from -9 to 7}} - s.a = 16; // expected-warning{{implicit truncation from 'int' to bitfield changes value from 16 to 0}} + s.a = -9; // expected-warning{{implicit truncation from 'int' to bit-field changes value from -9 to 7}} + s.a = 16; // expected-warning{{implicit truncation from 'int' to bit-field changes value from 16 to 0}} } |