1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify %s -triple x86_64-pc-linux-gnu
2*67e74705SXin Li template<int I, int J>
3*67e74705SXin Li struct Bitfields {
4*67e74705SXin Li int simple : I; // expected-error{{bit-field 'simple' has zero width}}
5*67e74705SXin Li int parens : (J);
6*67e74705SXin Li };
7*67e74705SXin Li
test_Bitfields(Bitfields<0,5> * b)8*67e74705SXin Li void test_Bitfields(Bitfields<0, 5> *b) {
9*67e74705SXin Li (void)sizeof(Bitfields<10, 5>);
10*67e74705SXin Li (void)sizeof(Bitfields<0, 1>); // expected-note{{in instantiation of template class 'Bitfields<0, 1>' requested here}}
11*67e74705SXin Li }
12*67e74705SXin Li
13*67e74705SXin Li template<int I, int J>
14*67e74705SXin Li struct BitfieldPlus {
15*67e74705SXin Li int bitfield : I + J; // expected-error{{bit-field 'bitfield' has zero width}}
16*67e74705SXin Li };
17*67e74705SXin Li
test_BitfieldPlus()18*67e74705SXin Li void test_BitfieldPlus() {
19*67e74705SXin Li (void)sizeof(BitfieldPlus<0, 1>);
20*67e74705SXin Li (void)sizeof(BitfieldPlus<-5, 5>); // expected-note{{in instantiation of template class 'BitfieldPlus<-5, 5>' requested here}}
21*67e74705SXin Li }
22*67e74705SXin Li
23*67e74705SXin Li template<int I, int J>
24*67e74705SXin Li struct BitfieldMinus {
25*67e74705SXin Li int bitfield : I - J; // expected-error{{bit-field 'bitfield' has negative width (-1)}} \
26*67e74705SXin Li // expected-error{{bit-field 'bitfield' has zero width}}
27*67e74705SXin Li };
28*67e74705SXin Li
test_BitfieldMinus()29*67e74705SXin Li void test_BitfieldMinus() {
30*67e74705SXin Li (void)sizeof(BitfieldMinus<5, 1>);
31*67e74705SXin Li (void)sizeof(BitfieldMinus<0, 1>); // expected-note{{in instantiation of template class 'BitfieldMinus<0, 1>' requested here}}
32*67e74705SXin Li (void)sizeof(BitfieldMinus<5, 5>); // expected-note{{in instantiation of template class 'BitfieldMinus<5, 5>' requested here}}
33*67e74705SXin Li }
34*67e74705SXin Li
35*67e74705SXin Li template<int I, int J>
36*67e74705SXin Li struct BitfieldDivide {
37*67e74705SXin Li int bitfield : I / J; // expected-error{{expression is not an integral constant expression}} \
38*67e74705SXin Li // expected-note{{division by zero}}
39*67e74705SXin Li };
40*67e74705SXin Li
test_BitfieldDivide()41*67e74705SXin Li void test_BitfieldDivide() {
42*67e74705SXin Li (void)sizeof(BitfieldDivide<5, 1>);
43*67e74705SXin Li (void)sizeof(BitfieldDivide<5, 0>); // expected-note{{in instantiation of template class 'BitfieldDivide<5, 0>' requested here}}
44*67e74705SXin Li }
45*67e74705SXin Li
46*67e74705SXin Li template<typename T, T I, int J>
47*67e74705SXin Li struct BitfieldDep {
48*67e74705SXin Li int bitfield : I + J;
49*67e74705SXin Li };
50*67e74705SXin Li
test_BitfieldDep()51*67e74705SXin Li void test_BitfieldDep() {
52*67e74705SXin Li (void)sizeof(BitfieldDep<int, 1, 5>);
53*67e74705SXin Li }
54*67e74705SXin Li
55*67e74705SXin Li template<int I>
56*67e74705SXin Li struct BitfieldNeg {
57*67e74705SXin Li int bitfield : (-I); // expected-error{{bit-field 'bitfield' has negative width (-5)}}
58*67e74705SXin Li };
59*67e74705SXin Li
60*67e74705SXin Li template<typename T, T I>
61*67e74705SXin Li struct BitfieldNeg2 {
62*67e74705SXin Li int bitfield : (-I); // expected-error{{bit-field 'bitfield' has negative width (-5)}}
63*67e74705SXin Li };
64*67e74705SXin Li
test_BitfieldNeg()65*67e74705SXin Li void test_BitfieldNeg() {
66*67e74705SXin Li (void)sizeof(BitfieldNeg<-5>); // okay
67*67e74705SXin Li (void)sizeof(BitfieldNeg<5>); // expected-note{{in instantiation of template class 'BitfieldNeg<5>' requested here}}
68*67e74705SXin Li (void)sizeof(BitfieldNeg2<int, -5>); // okay
69*67e74705SXin Li (void)sizeof(BitfieldNeg2<int, 5>); // expected-note{{in instantiation of template class 'BitfieldNeg2<int, 5>' requested here}}
70*67e74705SXin Li }
71*67e74705SXin Li
72*67e74705SXin Li template<typename T>
increment(T & x)73*67e74705SXin Li void increment(T &x) {
74*67e74705SXin Li (void)++x;
75*67e74705SXin Li }
76*67e74705SXin Li
77*67e74705SXin Li struct Incrementable {
78*67e74705SXin Li Incrementable &operator++();
79*67e74705SXin Li };
80*67e74705SXin Li
test_increment(Incrementable inc)81*67e74705SXin Li void test_increment(Incrementable inc) {
82*67e74705SXin Li increment(inc);
83*67e74705SXin Li }
84*67e74705SXin Li
85*67e74705SXin Li template<typename T>
add(const T & x)86*67e74705SXin Li void add(const T &x) {
87*67e74705SXin Li (void)(x + x);
88*67e74705SXin Li }
89*67e74705SXin Li
90*67e74705SXin Li namespace PR6237 {
91*67e74705SXin Li template <typename T>
f(T t)92*67e74705SXin Li void f(T t) {
93*67e74705SXin Li t++;
94*67e74705SXin Li }
95*67e74705SXin Li
96*67e74705SXin Li struct B { };
97*67e74705SXin Li B operator++(B &, int);
98*67e74705SXin Li
99*67e74705SXin Li template void f(B);
100*67e74705SXin Li }
101*67e74705SXin Li
102*67e74705SXin Li struct Addable {
103*67e74705SXin Li Addable operator+(const Addable&) const;
104*67e74705SXin Li };
105*67e74705SXin Li
test_add(Addable & a)106*67e74705SXin Li void test_add(Addable &a) {
107*67e74705SXin Li add(a);
108*67e74705SXin Li }
109*67e74705SXin Li
110*67e74705SXin Li struct CallOperator {
111*67e74705SXin Li int &operator()(int);
112*67e74705SXin Li double &operator()(double);
113*67e74705SXin Li };
114*67e74705SXin Li
115*67e74705SXin Li template<typename Result, typename F, typename Arg1>
test_call_operator(F f,Arg1 arg1)116*67e74705SXin Li Result test_call_operator(F f, Arg1 arg1) {
117*67e74705SXin Li // PR5266: non-dependent invocations of a function call operator.
118*67e74705SXin Li CallOperator call_op;
119*67e74705SXin Li int &ir = call_op(17);
120*67e74705SXin Li return f(arg1);
121*67e74705SXin Li }
122*67e74705SXin Li
test_call_operator(CallOperator call_op,int i,double d)123*67e74705SXin Li void test_call_operator(CallOperator call_op, int i, double d) {
124*67e74705SXin Li int &ir = test_call_operator<int&>(call_op, i);
125*67e74705SXin Li double &dr = test_call_operator<double&>(call_op, d);
126*67e74705SXin Li }
127*67e74705SXin Li
128*67e74705SXin Li template<typename T>
test_asm(T t)129*67e74705SXin Li void test_asm(T t) {
130*67e74705SXin Li asm ("nop" : "=r"(*t) : "r"(*t)); // expected-error {{indirection requires pointer operand ('int' invalid)}}
131*67e74705SXin Li }
132*67e74705SXin Li
test_asm()133*67e74705SXin Li void test_asm() {
134*67e74705SXin Li int* a;
135*67e74705SXin Li test_asm(a);
136*67e74705SXin Li
137*67e74705SXin Li int b;
138*67e74705SXin Li test_asm(b); // expected-note {{in instantiation of function template specialization 'test_asm<int>' requested here}}
139*67e74705SXin Li }
140*67e74705SXin Li
141*67e74705SXin Li namespace PR6424 {
142*67e74705SXin Li template<int I> struct X {
XPR6424::X143*67e74705SXin Li X() {
144*67e74705SXin Li int *ip = I; // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}}
145*67e74705SXin Li }
146*67e74705SXin Li };
147*67e74705SXin Li
148*67e74705SXin Li template<int> struct Y {
149*67e74705SXin Li typedef X<7> X7;
150*67e74705SXin Li
fPR6424::Y151*67e74705SXin Li void f() { X7(); } // expected-note{{instantiation}}
152*67e74705SXin Li };
153*67e74705SXin Li
154*67e74705SXin Li template void Y<3>::f();
155*67e74705SXin Li
156*67e74705SXin Li template<int I>
157*67e74705SXin Li struct X2 {
operator newPR6424::X2158*67e74705SXin Li void *operator new(__SIZE_TYPE__) {
159*67e74705SXin Li int *ip = I; // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}}
160*67e74705SXin Li return ip;
161*67e74705SXin Li }
162*67e74705SXin Li };
163*67e74705SXin Li
164*67e74705SXin Li template<int> struct Y2 {
165*67e74705SXin Li typedef X2<7> X;
fPR6424::Y2166*67e74705SXin Li void f() {
167*67e74705SXin Li new X(); // expected-note{{instantiation of}}
168*67e74705SXin Li }
169*67e74705SXin Li };
170*67e74705SXin Li
171*67e74705SXin Li template void Y2<3>::f();
172*67e74705SXin Li
173*67e74705SXin Li template<typename T>
rdar10283928(int count)174*67e74705SXin Li void rdar10283928(int count) {
175*67e74705SXin Li (void)new char[count]();
176*67e74705SXin Li }
177*67e74705SXin Li
178*67e74705SXin Li template void rdar10283928<int>(int);
179*67e74705SXin Li }
180*67e74705SXin Li
181*67e74705SXin Li namespace PR10864 {
182*67e74705SXin Li template<typename T> class Vals {};
183*67e74705SXin Li template<> class Vals<int> { public: static const int i = 1; };
184*67e74705SXin Li template<> class Vals<float> { public: static const double i; };
test_asm_tied(T o)185*67e74705SXin Li template<typename T> void test_asm_tied(T o) {
186*67e74705SXin Li __asm("addl $1, %0" : "=r" (o) : "0"(Vals<T>::i)); // expected-error {{input with type 'double' matching output with type 'float'}}
187*67e74705SXin Li }
test_asm_tied()188*67e74705SXin Li void test_asm_tied() {
189*67e74705SXin Li test_asm_tied(1);
190*67e74705SXin Li test_asm_tied(1.f); // expected-note {{instantiation of}}
191*67e74705SXin Li }
192*67e74705SXin Li }
193