summaryrefslogtreecommitdiffstats
path: root/test/SemaTemplate/instantiate-expr-1.cpp
blob: d1b05f66a5863fae1ed597143787d45e9a02d6ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// RUN: %clang_cc1 -fsyntax-only -verify %s
template<int I, int J>
struct Bitfields {
  int simple : I; // expected-error{{bit-field 'simple' has zero width}}
  int parens : (J);
};

void test_Bitfields(Bitfields<0, 5> *b) {
  (void)sizeof(Bitfields<10, 5>);
  (void)sizeof(Bitfields<0, 1>); // expected-note{{in instantiation of template class 'struct Bitfields<0, 1>' requested here}}
}

template<int I, int J>
struct BitfieldPlus {
  int bitfield : I + J; // expected-error{{bit-field 'bitfield' has zero width}}
};

void test_BitfieldPlus() {
  (void)sizeof(BitfieldPlus<0, 1>);
  (void)sizeof(BitfieldPlus<-5, 5>); // expected-note{{in instantiation of template class 'struct BitfieldPlus<-5, 5>' requested here}}
}

template<int I, int J>
struct BitfieldMinus {
  int bitfield : I - J; // expected-error{{bit-field 'bitfield' has negative width (-1)}} \
  // expected-error{{bit-field 'bitfield' has zero width}}
};

void test_BitfieldMinus() {
  (void)sizeof(BitfieldMinus<5, 1>);
  (void)sizeof(BitfieldMinus<0, 1>); // expected-note{{in instantiation of template class 'struct BitfieldMinus<0, 1>' requested here}}
  (void)sizeof(BitfieldMinus<5, 5>); // expected-note{{in instantiation of template class 'struct BitfieldMinus<5, 5>' requested here}}
}

template<int I, int J>
struct BitfieldDivide {
  int bitfield : I / J; // expected-error{{expression is not an integer constant expression}} \
                        // expected-note{{division by zero}}
};

void test_BitfieldDivide() {
  (void)sizeof(BitfieldDivide<5, 1>);
  (void)sizeof(BitfieldDivide<5, 0>); // expected-note{{in instantiation of template class 'struct BitfieldDivide<5, 0>' requested here}}
}

template<typename T, T I, int J>
struct BitfieldDep {
  int bitfield : I + J;
};

void test_BitfieldDep() {
  (void)sizeof(BitfieldDep<int, 1, 5>);
}

template<int I>
struct BitfieldNeg {
  int bitfield : (-I); // expected-error{{bit-field 'bitfield' has negative width (-5)}}
};

template<typename T, T I>
struct BitfieldNeg2 {
  int bitfield : (-I); // expected-error{{bit-field 'bitfield' has negative width (-5)}}
};

void test_BitfieldNeg() {
  (void)sizeof(BitfieldNeg<-5>); // okay
  (void)sizeof(BitfieldNeg<5>); // expected-note{{in instantiation of template class 'struct BitfieldNeg<5>' requested here}}
  (void)sizeof(BitfieldNeg2<int, -5>); // okay
  (void)sizeof(BitfieldNeg2<int, 5>); // expected-note{{in instantiation of template class 'struct BitfieldNeg2<int, 5>' requested here}}
}

template<typename T>
void increment(T &x) {
  (void)++x;
}

struct Incrementable {
  Incrementable &operator++();
};

void test_increment(Incrementable inc) {
  increment(inc);
}

template<typename T>
void add(const T &x) {
  (void)(x + x);
}

namespace PR6237 {
  template <typename T>
  void f(T t) {
    t++;
  }

  struct B { };
  B operator++(B &, int);

  template void f(B);
}

struct Addable {
  Addable operator+(const Addable&) const;
};

void test_add(Addable &a) {
  add(a);
}

struct CallOperator {
  int &operator()(int);
  double &operator()(double);
};

template<typename Result, typename F, typename Arg1>
Result test_call_operator(F f, Arg1 arg1) {
  // PR5266: non-dependent invocations of a function call operator.
  CallOperator call_op;
  int &ir = call_op(17);
  return f(arg1);
}

void test_call_operator(CallOperator call_op, int i, double d) {
  int &ir = test_call_operator<int&>(call_op, i);
  double &dr = test_call_operator<double&>(call_op, d);
}

template<typename T>
void test_asm(T t) {
  asm ("nop" : "=a"(*t) : "r"(*t)); // expected-error {{indirection requires pointer operand ('int' invalid)}}
}

void test_asm() {
  int* a;
  test_asm(a);
  
  int b;
  test_asm(b); // expected-note {{in instantiation of function template specialization 'test_asm<int>' requested here}}
}
OpenPOWER on IntegriCloud