Douglas Gregor | a0e500d | 2009-03-12 16:53:44 +0000 | [diff] [blame] | 1 | // RUN: clang -fsyntax-only -verify %s |
| 2 | |
| 3 | template<int I, int J> |
| 4 | struct Bitfields { |
| 5 | int simple : I; // expected-error{{bit-field 'simple' has zero width}} |
| 6 | int parens : (J); |
| 7 | }; |
| 8 | |
| 9 | void test_Bitfields(Bitfields<0, 5> *b) { |
| 10 | (void)sizeof(Bitfields<10, 5>); |
| 11 | (void)sizeof(Bitfields<0, 1>); // expected-note{{in instantiation of template class 'struct Bitfields<0, 1>' requested here}} |
| 12 | } |
Douglas Gregor | df03251 | 2009-03-12 22:46:12 +0000 | [diff] [blame] | 13 | |
| 14 | template<int I, int J> |
| 15 | struct BitfieldPlus { |
| 16 | int bitfield : I + J; // expected-error{{bit-field 'bitfield' has zero width}} |
| 17 | }; |
| 18 | |
| 19 | void test_BitfieldPlus() { |
| 20 | (void)sizeof(BitfieldPlus<0, 1>); |
| 21 | (void)sizeof(BitfieldPlus<-5, 5>); // expected-note{{in instantiation of template class 'struct BitfieldPlus<-5, 5>' requested here}} |
| 22 | } |
| 23 | |
| 24 | template<int I, int J> |
| 25 | struct BitfieldMinus { |
| 26 | int bitfield : I - J; // expected-error{{bit-field 'bitfield' has negative width (-1)}} \ |
| 27 | // expected-error{{bit-field 'bitfield' has zero width}} |
| 28 | }; |
| 29 | |
| 30 | void test_BitfieldMinus() { |
| 31 | (void)sizeof(BitfieldMinus<5, 1>); |
| 32 | (void)sizeof(BitfieldMinus<0, 1>); // expected-note{{in instantiation of template class 'struct BitfieldMinus<0, 1>' requested here}} |
| 33 | (void)sizeof(BitfieldMinus<5, 5>); // expected-note{{in instantiation of template class 'struct BitfieldMinus<5, 5>' requested here}} |
| 34 | } |
| 35 | |
| 36 | template<int I, int J> |
| 37 | struct BitfieldDivide { |
| 38 | int bitfield : I / J; // expected-error{{expression is not an integer constant expression}} \ |
| 39 | // expected-note{{division by zero}} |
| 40 | }; |
| 41 | |
| 42 | void test_BitfieldDivide() { |
| 43 | (void)sizeof(BitfieldDivide<5, 1>); |
| 44 | (void)sizeof(BitfieldDivide<5, 0>); // expected-note{{in instantiation of template class 'struct BitfieldDivide<5, 0>' requested here}} |
| 45 | } |
Douglas Gregor | ba49817 | 2009-03-13 21:01:28 +0000 | [diff] [blame] | 46 | |
| 47 | template<typename T, T I, int J> |
| 48 | struct BitfieldDep { |
| 49 | int bitfield : I + J; |
| 50 | }; |
| 51 | |
| 52 | void test_BitfieldDep() { |
| 53 | (void)sizeof(BitfieldDep<int, 1, 5>); |
| 54 | } |
| 55 | |
Douglas Gregor | bc736fc | 2009-03-13 23:49:33 +0000 | [diff] [blame] | 56 | template<int I> |
| 57 | struct BitfieldNeg { |
| 58 | int bitfield : (-I); // expected-error{{bit-field 'bitfield' has negative width (-5)}} |
| 59 | }; |
| 60 | |
| 61 | template<typename T, T I> |
| 62 | struct BitfieldNeg2 { |
| 63 | int bitfield : (-I); // expected-error{{bit-field 'bitfield' has negative width (-5)}} |
| 64 | }; |
| 65 | |
| 66 | void test_BitfieldNeg() { |
| 67 | (void)sizeof(BitfieldNeg<-5>); // okay |
| 68 | (void)sizeof(BitfieldNeg<5>); // expected-note{{in instantiation of template class 'struct BitfieldNeg<5>' requested here}} |
| 69 | (void)sizeof(BitfieldNeg2<int, -5>); // okay |
| 70 | (void)sizeof(BitfieldNeg2<int, 5>); // expected-note{{in instantiation of template class 'struct BitfieldNeg2<int, 5>' requested here}} |
| 71 | } |