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