instantiate-expr-1.cpp revision bc736fceca6f0bca31d16003a7587857190408fb
1// RUN: clang -fsyntax-only -verify %s
2
3template<int I, int J>
4struct Bitfields {
5  int simple : I; // expected-error{{bit-field 'simple' has zero width}}
6  int parens : (J);
7};
8
9void 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}
13
14template<int I, int J>
15struct BitfieldPlus {
16  int bitfield : I + J; // expected-error{{bit-field 'bitfield' has zero width}}
17};
18
19void 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
24template<int I, int J>
25struct 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
30void 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
36template<int I, int J>
37struct BitfieldDivide {
38  int bitfield : I / J; // expected-error{{expression is not an integer constant expression}} \
39                        // expected-note{{division by zero}}
40};
41
42void 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}
46
47template<typename T, T I, int J>
48struct BitfieldDep {
49  int bitfield : I + J;
50};
51
52void test_BitfieldDep() {
53  (void)sizeof(BitfieldDep<int, 1, 5>);
54}
55
56template<int I>
57struct BitfieldNeg {
58  int bitfield : (-I); // expected-error{{bit-field 'bitfield' has negative width (-5)}}
59};
60
61template<typename T, T I>
62struct BitfieldNeg2 {
63  int bitfield : (-I); // expected-error{{bit-field 'bitfield' has negative width (-5)}}
64};
65
66void 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}
72