xref: /llvm-project/clang/test/SemaTemplate/instantiate-expr-1.cpp (revision 0950e41b73587a71ee66c88cf8db0dfff343a8cf)
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 }
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 }
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 
56