blob: 5752033fbd364f2924bc432f79a6f6ac2811b3de [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Douglas Gregora0e500d2009-03-12 16:53:44 +00002template<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}
Douglas Gregordf032512009-03-12 22:46:12 +000012
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}} \
Chris Lattner7ef655a2010-01-12 21:23:57 +000038 // expected-note{{division by zero}} \
39 // expected-warning {{division by zero is undefined}}
Douglas Gregordf032512009-03-12 22:46:12 +000040};
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}
Douglas Gregorba498172009-03-13 21:01:28 +000046
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
Douglas Gregorbc736fc2009-03-13 23:49:33 +000056template<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}
Douglas Gregor6ca7cfb2009-11-05 00:51:44 +000072
73template<typename T>
74void increment(T &x) {
75 (void)++x;
76}
77
78struct Incrementable {
79 Incrementable &operator++();
80};
81
82void test_increment(Incrementable inc) {
83 increment(inc);
84}
85
86template<typename T>
87void add(const T &x) {
88 (void)(x + x);
89}
90
91struct Addable {
92 Addable operator+(const Addable&) const;
93};
94
95void test_add(Addable &a) {
96 add(a);
97}
Douglas Gregor668d6d92009-12-13 20:44:55 +000098
99struct CallOperator {
100 int &operator()(int);
101 double &operator()(double);
102};
103
104template<typename Result, typename F, typename Arg1>
105Result test_call_operator(F f, Arg1 arg1) {
106 // PR5266: non-dependent invocations of a function call operator.
107 CallOperator call_op;
108 int &ir = call_op(17);
109 return f(arg1);
110}
111
112void test_call_operator(CallOperator call_op, int i, double d) {
113 int &ir = test_call_operator<int&>(call_op, i);
114 double &dr = test_call_operator<double&>(call_op, d);
115}