11#include < cstdint>
22
3- template < typename T, T y> class C1 {
3+ class C1 {
44public:
5- C1 () : x(y) {}
5+ C1 (unsigned char y ) : x(y) {}
66
77private:
88 unsigned char x;
99};
1010
11- template < typename T, T y> class C2 {
11+ class C2 {
1212public:
13- C2 () : x(y) {}
13+ C2 (signed char y ) : x(y) {}
1414
1515private:
1616 signed char x;
1717};
1818
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 {
2121public:
22- C5 () : x(y) {}
22+ C5 (unsigned char y ) : x(y) {}
2323
2424private:
2525 std::uint8_t x;
2626};
2727
28- template < typename T, T y> class C6 {
28+ class C6 {
2929public:
30- C6 () : x(y) {}
30+ C6 (signed char y ) : x(y) {}
3131
3232private:
3333 std::int8_t x;
@@ -40,69 +40,6 @@ void f2(signed char x) {}
4040void f9 (std::uint8_t x) {}
4141void f10 (std::int8_t x) {}
4242
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-
10643int main () {
10744
10845 /* ========== 1. Assigning a char to another char ========== */
@@ -138,30 +75,30 @@ int main() {
13875
13976 /* ===== 1-2. Assigning a char to a char member ===== */
14077
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
14380
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
14683
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
14986
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
15289
15390 /* 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
15693
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
15996
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
16299
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
165102
166103 /* ========== 1-3. Assigning a char to a char through a pointer ========== */
167104
@@ -206,9 +143,6 @@ int main() {
206143
207144 /* ========== 2. Passing a char argument to a char parameter ========== */
208145
209- /* ===== 2-1. Passing char argument to a char parameter of a regular function
210- * ===== */
211-
212146 unsigned char a1 = 1 ;
213147 f1 (a1); // COMPLIANT: unsigned char arg passed to an unsigned char parameter
214148
@@ -233,81 +167,4 @@ int main() {
233167
234168 char a8 = ' a' ;
235169 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
313170}
0 commit comments