instantiate-expr-1.cpp revision 668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9
1// RUN: clang-cc -fsyntax-only -verify %s
2template<int I, int J>
3struct Bitfields {
4  int simple : I; // expected-error{{bit-field 'simple' has zero width}}
5  int parens : (J);
6};
7
8void test_Bitfields(Bitfields<0, 5> *b) {
9  (void)sizeof(Bitfields<10, 5>);
10  (void)sizeof(Bitfields<0, 1>); // expected-note{{in instantiation of template class 'struct Bitfields<0, 1>' requested here}}
11}
12
13template<int I, int J>
14struct BitfieldPlus {
15  int bitfield : I + J; // expected-error{{bit-field 'bitfield' has zero width}}
16};
17
18void test_BitfieldPlus() {
19  (void)sizeof(BitfieldPlus<0, 1>);
20  (void)sizeof(BitfieldPlus<-5, 5>); // expected-note{{in instantiation of template class 'struct BitfieldPlus<-5, 5>' requested here}}
21}
22
23template<int I, int J>
24struct BitfieldMinus {
25  int bitfield : I - J; // expected-error{{bit-field 'bitfield' has negative width (-1)}} \
26  // expected-error{{bit-field 'bitfield' has zero width}}
27};
28
29void test_BitfieldMinus() {
30  (void)sizeof(BitfieldMinus<5, 1>);
31  (void)sizeof(BitfieldMinus<0, 1>); // expected-note{{in instantiation of template class 'struct BitfieldMinus<0, 1>' requested here}}
32  (void)sizeof(BitfieldMinus<5, 5>); // expected-note{{in instantiation of template class 'struct BitfieldMinus<5, 5>' requested here}}
33}
34
35template<int I, int J>
36struct BitfieldDivide {
37  int bitfield : I / J; // expected-error{{expression is not an integer constant expression}} \
38                        // expected-note{{division by zero}}
39};
40
41void test_BitfieldDivide() {
42  (void)sizeof(BitfieldDivide<5, 1>);
43  (void)sizeof(BitfieldDivide<5, 0>); // expected-note{{in instantiation of template class 'struct BitfieldDivide<5, 0>' requested here}}
44}
45
46template<typename T, T I, int J>
47struct BitfieldDep {
48  int bitfield : I + J;
49};
50
51void test_BitfieldDep() {
52  (void)sizeof(BitfieldDep<int, 1, 5>);
53}
54
55template<int I>
56struct BitfieldNeg {
57  int bitfield : (-I); // expected-error{{bit-field 'bitfield' has negative width (-5)}}
58};
59
60template<typename T, T I>
61struct BitfieldNeg2 {
62  int bitfield : (-I); // expected-error{{bit-field 'bitfield' has negative width (-5)}}
63};
64
65void test_BitfieldNeg() {
66  (void)sizeof(BitfieldNeg<-5>); // okay
67  (void)sizeof(BitfieldNeg<5>); // expected-note{{in instantiation of template class 'struct BitfieldNeg<5>' requested here}}
68  (void)sizeof(BitfieldNeg2<int, -5>); // okay
69  (void)sizeof(BitfieldNeg2<int, 5>); // expected-note{{in instantiation of template class 'struct BitfieldNeg2<int, 5>' requested here}}
70}
71
72template<typename T>
73void increment(T &x) {
74  (void)++x;
75}
76
77struct Incrementable {
78  Incrementable &operator++();
79};
80
81void test_increment(Incrementable inc) {
82  increment(inc);
83}
84
85template<typename T>
86void add(const T &x) {
87  (void)(x + x);
88}
89
90struct Addable {
91  Addable operator+(const Addable&) const;
92};
93
94void test_add(Addable &a) {
95  add(a);
96}
97
98struct CallOperator {
99  int &operator()(int);
100  double &operator()(double);
101};
102
103template<typename Result, typename F, typename Arg1>
104Result test_call_operator(F f, Arg1 arg1) {
105  // PR5266: non-dependent invocations of a function call operator.
106  CallOperator call_op;
107  int &ir = call_op(17);
108  return f(arg1);
109}
110
111void test_call_operator(CallOperator call_op, int i, double d) {
112  int &ir = test_call_operator<int&>(call_op, i);
113  double &dr = test_call_operator<double&>(call_op, d);
114}
115