1
1
#include < cstdint>
2
2
3
- template < typename T, T y> class C1 {
3
+ class C1 {
4
4
public:
5
- C1 () : x(y) {}
5
+ C1 (unsigned char y ) : x(y) {}
6
6
7
7
private:
8
8
unsigned char x;
9
9
};
10
10
11
- template < typename T, T y> class C2 {
11
+ class C2 {
12
12
public:
13
- C2 () : x(y) {}
13
+ C2 (signed char y ) : x(y) {}
14
14
15
15
private:
16
16
signed char x;
17
17
};
18
18
19
- /* Twin templates for std::uint8_t and std::int8_t */
20
- template < typename T, T y> class C5 {
19
+ /* Twin classes for std::uint8_t and std::int8_t */
20
+ class C5 {
21
21
public:
22
- C5 () : x(y) {}
22
+ C5 (unsigned char y ) : x(y) {}
23
23
24
24
private:
25
25
std::uint8_t x;
26
26
};
27
27
28
- template < typename T, T y> class C6 {
28
+ class C6 {
29
29
public:
30
- C6 () : x(y) {}
30
+ C6 (signed char y ) : x(y) {}
31
31
32
32
private:
33
33
std::int8_t x;
@@ -40,69 +40,6 @@ void f2(signed char x) {}
40
40
void f9 (std::uint8_t x) {}
41
41
void f10 (std::int8_t x) {}
42
42
43
- template <typename T> void f5 (T x) { unsigned char y = x; }
44
- template <typename T> void f6 (T x) { signed char y = x; }
45
-
46
- /* Twin template functions for std::uint8_t and std::int8_t */
47
- template <typename T> void f13 (T x) { std::uint8_t y = x; }
48
- template <typename T> void f14 (T x) { std::int8_t y = x; }
49
-
50
- template <typename T> class C9 {
51
- public:
52
- C9 (T y) : x(y) {}
53
-
54
- private:
55
- unsigned char x;
56
- };
57
-
58
- template <typename T> class C10 {
59
- public:
60
- C10 (T y) : x(y) {}
61
-
62
- private:
63
- signed char x;
64
- };
65
-
66
- /* Twin template classes for std::uint8_t and std::int8_t */
67
- template <typename T> class C13 {
68
- public:
69
- C13 (T y) : x(y) {}
70
-
71
- private:
72
- std::uint8_t x;
73
- };
74
-
75
- template <typename T> class C14 {
76
- public:
77
- C14 (T y) : x(y) {}
78
-
79
- private:
80
- std::int8_t x;
81
- };
82
-
83
- template <typename T> T v1;
84
- template <typename T> T v2;
85
-
86
- void instantiateTemplateVariables () {
87
- v1<unsigned char > =
88
- 1 ; // COMPLIANT: unsigned char assigned to an unsigned char
89
- v2<signed char > = 1 ; // COMPLIANT: signed char assigned to a signed char
90
- v2<char > = ' v' ; // COMPLIANT: plain char assigned to a plain char
91
-
92
- v1<unsigned char > =
93
- ' v' ; // NON-COMPLIANT: plain char assigned to an unsigned char
94
- v2<signed char > = ' v' ; // NON-COMPLIANT: plain char assigned to a signed char
95
-
96
- /* Twin cases with std::uint8_t and std::int8_t */
97
- v1<std::uint8_t > = 1 ; // COMPLIANT: std::uint8_t assigned to a std::uint8_t
98
- v2<std::int8_t > = 1 ; // COMPLIANT: std::int8_t assigned to a std::int8_t
99
- v2<char > = ' v' ; // COMPLIANT: plain char assigned to a plain char
100
-
101
- v1<std::uint8_t > =
102
- ' v' ; // NON-COMPLIANT: plain char assigned to a std::uint8_t
103
- v2<std::int8_t > = ' v' ; // NON-COMPLIANT: plain char assigned to a std::int8_t
104
- }
105
-
106
43
int main () {
107
44
108
45
/* ========== 1. Assigning a char to another char ========== */
@@ -138,30 +75,30 @@ int main() {
138
75
139
76
/* ===== 1-2. Assigning a char to a char member ===== */
140
77
141
- C1< unsigned char , 1 > c1 ; // COMPLIANT: unsigned char arg passed to an unsigned
142
- // char member through a template
78
+ C1 c1 ( 1 ) ; // COMPLIANT: unsigned char arg passed to an unsigned
79
+ // char member
143
80
144
- C2< signed char , 1 > c2 ; // COMPLIANT: signed char arg passed to a signed char
145
- // member through a template
81
+ C2 c2 ( 1 ) ; // COMPLIANT: signed char arg passed to a signed char
82
+ // member
146
83
147
- C1< char , ' x' > c3 ; // NON-COMPLIANT: plain char arg passed to an unsigned char
148
- // member through a template
84
+ C1 c3 ( ' x' ) ; // NON-COMPLIANT: plain char arg passed to an unsigned char
85
+ // member
149
86
150
- C2< char , ' x' > c4 ; // NON-COMPLIANT: plain char arg passed to a signed char
151
- // member through a template
87
+ C2 c4 ( ' x' ) ; // NON-COMPLIANT: plain char arg passed to a signed char
88
+ // member
152
89
153
90
/* Twin cases with std::uint8_t and std::int8_t */
154
- C5<std:: uint8_t , 1 > c5 ; // COMPLIANT: std::uint8_t arg passed to a
155
- // std::uint8_t member through a template
91
+ C5 c5 ( 1 ) ; // COMPLIANT: std::uint8_t arg passed to a
92
+ // std::uint8_t member
156
93
157
- C6<std:: int8_t , 1 > c6 ; // COMPLIANT: std::int8_t arg passed to a std::int8_t
158
- // member through a template
94
+ C6 c6 ( 1 ) ; // COMPLIANT: std::int8_t arg passed to a std::int8_t
95
+ // member
159
96
160
- C5< char , 1 > c7 ; // NON-COMPLIANT: plain char arg passed to a
161
- // std::uint8_t member through a template
97
+ C5 c7 ( ' x ' ) ; // NON-COMPLIANT: plain char arg passed to a
98
+ // std::uint8_t member
162
99
163
- C6< char , 1 > c8 ; // NON-COMPLIANT: plain char arg passed to a std::int8_t
164
- // member through a template
100
+ C6 c8 ( ' x ' ) ; // NON-COMPLIANT: plain char arg passed to a std::int8_t
101
+ // member
165
102
166
103
/* ========== 1-3. Assigning a char to a char through a pointer ========== */
167
104
@@ -206,9 +143,6 @@ int main() {
206
143
207
144
/* ========== 2. Passing a char argument to a char parameter ========== */
208
145
209
- /* ===== 2-1. Passing char argument to a char parameter of a regular function
210
- * ===== */
211
-
212
146
unsigned char a1 = 1 ;
213
147
f1 (a1); // COMPLIANT: unsigned char arg passed to an unsigned char parameter
214
148
@@ -233,81 +167,4 @@ int main() {
233
167
234
168
char a8 = ' a' ;
235
169
f10 (a8); // NON-COMPLIANT: plain char arg passed to a std::int8_t parameter
236
-
237
- /* ===== 2-2. Passing char argument to a char parameter through a template
238
- * ===== */
239
-
240
- unsigned char a9 = 1 ;
241
- f5 (a9); // COMPLIANT: unsigned char arg passed to an unsigned char parameter
242
- // through a template
243
-
244
- signed char a10 = 1 ;
245
- f6 (a10); // COMPLIANT: signed char arg passed to a signed char parameter
246
- // through a template
247
-
248
- char a11 = ' a' ;
249
- f5 (a11); // NON-COMPLIANT: plain char arg passed to an unsigned char parameter
250
- // through a template
251
-
252
- char a12 = ' a' ;
253
- f6 (a12); // NON-COMPLIANT: plain char arg passed to a signed char parameter
254
- // through a template
255
-
256
- /* Twin cases with std::uint8_t and std::int8_t */
257
- std::uint8_t a13 = 1 ;
258
- f13 (a13); // COMPLIANT: std::uint8_t arg passed to a std::uint8_t parameter
259
- // through a template
260
-
261
- std::int8_t a14 = 1 ;
262
- f14 (a14); // COMPLIANT: std::int8_t arg passed to a std::int8_t parameter
263
- // through a template
264
-
265
- char a15 = ' a' ;
266
- f13 (a15); // NON-COMPLIANT: plain char arg passed to a std::uint8_t parameter
267
- // through a template
268
-
269
- char a16 = ' a' ;
270
- f14 (a16); // NON-COMPLIANT: plain char arg passed to a std::int8_t parameter
271
- // through a template
272
-
273
- /* ========== 2-3. Passing a char argument to a char parameter through a
274
- * template ========== */
275
-
276
- unsigned char a17 = 1 ;
277
- C9<unsigned char > c9 (
278
- a17); // COMPLIANT: unsigned char arg passed to an unsigned char parameter
279
- // of a constructor through a template
280
-
281
- signed char a18 = 1 ;
282
- C10<signed char > c10 (
283
- a18); // COMPLIANT: signed char arg passed to an signed
284
- // char parameter of a constructor through a template
285
-
286
- char a19 = ' a' ;
287
- C9<char > c11 (
288
- a19); // NON-COMPLIANT: plain char arg passed to an unsigned signed char
289
- // parameter of a constructor through a template
290
-
291
- char a20 = ' a' ;
292
- C10<char > c12 (a20); // NON-COMPLIANT: plain char arg passed to an signed char
293
- // parameter of a constructor through a template
294
-
295
- /* Twin cases with std::uint8_t and std::int8_t */
296
- std::uint8_t a21 = 1 ;
297
- C13<std::uint8_t > c13 (
298
- a21); // COMPLIANT: std::uint8_t arg passed to a std::uint8_t parameter
299
- // of a constructor through a template
300
-
301
- std::int8_t a22 = 1 ;
302
- C14<std::int8_t > c14 (
303
- a22); // COMPLIANT: std::int8_t arg passed to a std::int8_t
304
- // parameter of a constructor through a template
305
-
306
- char a23 = ' a' ;
307
- C13<char > c15 (a23); // NON-COMPLIANT: plain char arg passed to a std::uint8_t
308
- // parameter of a constructor through a template
309
-
310
- char a24 = ' a' ;
311
- C14<char > c16 (a24); // NON-COMPLIANT: plain char arg passed to a std::int8_t
312
- // parameter of a constructor through a template
313
170
}
0 commit comments