Skip to content

Commit 8dbaa1b

Browse files
committed
Remove templates from the coverage of the query
Templates are tricky issue; we'd like to address this in a different PR.
1 parent 2991f6f commit 8dbaa1b

File tree

3 files changed

+44
-198
lines changed

3 files changed

+44
-198
lines changed

cpp/autosar/src/rules/M5-0-12/SignedCharAndUnsignedCharTypeShallOnlyBeUsedForTheStorageAndUseOfNumericValues.ql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ where
2929
) and
3030
/* 3. Check if the source expression is a plain char type, i.e. not explicitly signed / unsigned. */
3131
c.getExpr().getUnspecifiedType() instanceof PlainCharType
32-
select c, "Implicit conversion of plain char type to $@ with an explicitly signed char type", c,
33-
c.getUnspecifiedType().getName()
32+
select c,
33+
"This expression of plain char type is implicitly converted to '" +
34+
c.getUnspecifiedType().getName() + "'."
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,16 @@
1-
| test.cpp:93:7:93:9 | (unsigned char)... | Implicit conversion of plain char $@ to 'unsigned char'. | test.cpp:93:7:93:9 | 118 | expression |
2-
| test.cpp:94:21:94:23 | (signed char)... | Implicit conversion of plain char $@ to 'signed char'. | test.cpp:94:21:94:23 | 118 | expression |
3-
| test.cpp:102:7:102:9 | (unsigned char)... | Implicit conversion of plain char $@ to 'unsigned char'. | test.cpp:102:7:102:9 | 118 | expression |
4-
| test.cpp:103:21:103:23 | (signed char)... | Implicit conversion of plain char $@ to 'signed char'. | test.cpp:103:21:103:23 | 118 | expression |
5-
| test.cpp:121:7:121:8 | (unsigned char)... | Implicit conversion of plain char $@ to 'unsigned char'. | test.cpp:121:7:121:8 | x3 | expression |
6-
| test.cpp:124:20:124:21 | (signed char)... | Implicit conversion of plain char $@ to 'signed char'. | test.cpp:124:20:124:21 | x4 | expression |
7-
| test.cpp:134:21:134:22 | (uint8_t)... | Implicit conversion of plain char $@ to 'uint8_t'. | test.cpp:134:21:134:22 | x7 | expression |
8-
| test.cpp:137:20:137:21 | (int8_t)... | Implicit conversion of plain char $@ to 'int8_t'. | test.cpp:137:20:137:21 | x8 | expression |
9-
| test.cpp:147:17:147:18 | definition of c3 | Implicit conversion of plain char $@ to 'unsigned char' from instantiating template 'C1<T, y>'. | test.cpp:5:12:5:12 | 120 | expression |
10-
| test.cpp:150:17:150:18 | definition of c4 | Implicit conversion of plain char $@ to 'signed char' from instantiating template 'C2<T, y>'. | test.cpp:13:12:13:12 | 120 | expression |
11-
| test.cpp:160:15:160:16 | definition of c7 | Implicit conversion of plain char $@ to 'uint8_t' from instantiating template 'C5<T, y>'. | test.cpp:22:12:22:12 | 1 | expression |
12-
| test.cpp:163:15:163:16 | definition of c8 | Implicit conversion of plain char $@ to 'int8_t' from instantiating template 'C6<T, y>'. | test.cpp:30:12:30:12 | 1 | expression |
13-
| test.cpp:180:7:180:10 | (unsigned char)... | Implicit conversion of plain char $@ to 'unsigned char'. | test.cpp:180:7:180:10 | * ... | expression |
14-
| test.cpp:185:7:185:10 | (signed char)... | Implicit conversion of plain char $@ to 'signed char'. | test.cpp:185:7:185:10 | * ... | expression |
15-
| test.cpp:200:7:200:10 | (uint8_t)... | Implicit conversion of plain char $@ to 'uint8_t'. | test.cpp:200:7:200:10 | * ... | expression |
16-
| test.cpp:205:7:205:10 | (int8_t)... | Implicit conversion of plain char $@ to 'int8_t'. | test.cpp:205:7:205:10 | * ... | expression |
17-
| test.cpp:219:6:219:7 | (unsigned char)... | Implicit conversion of plain char $@ to 'unsigned char'. | test.cpp:219:6:219:7 | a3 | expression |
18-
| test.cpp:222:6:222:7 | (signed char)... | Implicit conversion of plain char $@ to 'signed char'. | test.cpp:222:6:222:7 | a4 | expression |
19-
| test.cpp:232:6:232:7 | (uint8_t)... | Implicit conversion of plain char $@ to 'uint8_t'. | test.cpp:232:6:232:7 | a7 | expression |
20-
| test.cpp:235:7:235:8 | (int8_t)... | Implicit conversion of plain char $@ to 'int8_t'. | test.cpp:235:7:235:8 | a8 | expression |
21-
| test.cpp:249:3:249:4 | call to f5 | Implicit conversion of plain char $@ to 'unsigned char' from instantiating template 'f5'. | test.cpp:43:56:43:56 | x | expression |
22-
| test.cpp:253:3:253:4 | call to f6 | Implicit conversion of plain char $@ to 'signed char' from instantiating template 'f6'. | test.cpp:44:54:44:54 | x | expression |
23-
| test.cpp:266:3:266:5 | call to f13 | Implicit conversion of plain char $@ to 'uint8_t' from instantiating template 'f13'. | test.cpp:47:56:47:56 | x | expression |
24-
| test.cpp:270:3:270:5 | call to f14 | Implicit conversion of plain char $@ to 'int8_t' from instantiating template 'f14'. | test.cpp:48:55:48:55 | x | expression |
25-
| test.cpp:287:12:287:14 | definition of c11 | Implicit conversion of plain char $@ to 'unsigned char' from instantiating template 'C9<T>'. | test.cpp:52:15:52:15 | y | expression |
26-
| test.cpp:292:13:292:15 | definition of c12 | Implicit conversion of plain char $@ to 'signed char' from instantiating template 'C10<T>'. | test.cpp:60:16:60:16 | y | expression |
27-
| test.cpp:307:13:307:15 | definition of c15 | Implicit conversion of plain char $@ to 'uint8_t' from instantiating template 'C13<T>'. | test.cpp:69:16:69:16 | y | expression |
28-
| test.cpp:311:13:311:15 | definition of c16 | Implicit conversion of plain char $@ to 'int8_t' from instantiating template 'C14<T>'. | test.cpp:77:16:77:16 | y | expression |
1+
| test.cpp:58:7:58:8 | (unsigned char)... | This expression of plain char type is implicitly converted to 'unsigned char'. |
2+
| test.cpp:61:20:61:21 | (signed char)... | This expression of plain char type is implicitly converted to 'signed char'. |
3+
| test.cpp:71:21:71:22 | (uint8_t)... | This expression of plain char type is implicitly converted to 'unsigned char'. |
4+
| test.cpp:74:20:74:21 | (int8_t)... | This expression of plain char type is implicitly converted to 'signed char'. |
5+
| test.cpp:84:9:84:11 | (unsigned char)... | This expression of plain char type is implicitly converted to 'unsigned char'. |
6+
| test.cpp:87:9:87:11 | (signed char)... | This expression of plain char type is implicitly converted to 'signed char'. |
7+
| test.cpp:97:9:97:11 | (unsigned char)... | This expression of plain char type is implicitly converted to 'unsigned char'. |
8+
| test.cpp:100:9:100:11 | (signed char)... | This expression of plain char type is implicitly converted to 'signed char'. |
9+
| test.cpp:117:7:117:10 | (unsigned char)... | This expression of plain char type is implicitly converted to 'unsigned char'. |
10+
| test.cpp:122:7:122:10 | (signed char)... | This expression of plain char type is implicitly converted to 'signed char'. |
11+
| test.cpp:137:7:137:10 | (uint8_t)... | This expression of plain char type is implicitly converted to 'unsigned char'. |
12+
| test.cpp:142:7:142:10 | (int8_t)... | This expression of plain char type is implicitly converted to 'signed char'. |
13+
| test.cpp:153:6:153:7 | (unsigned char)... | This expression of plain char type is implicitly converted to 'unsigned char'. |
14+
| test.cpp:156:6:156:7 | (signed char)... | This expression of plain char type is implicitly converted to 'signed char'. |
15+
| test.cpp:166:6:166:7 | (uint8_t)... | This expression of plain char type is implicitly converted to 'unsigned char'. |
16+
| test.cpp:169:7:169:8 | (int8_t)... | This expression of plain char type is implicitly converted to 'signed char'. |
Lines changed: 25 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
#include <cstdint>
22

3-
template <typename T, T y> class C1 {
3+
class C1 {
44
public:
5-
C1() : x(y) {}
5+
C1(unsigned char y) : x(y) {}
66

77
private:
88
unsigned char x;
99
};
1010

11-
template <typename T, T y> class C2 {
11+
class C2 {
1212
public:
13-
C2() : x(y) {}
13+
C2(signed char y) : x(y) {}
1414

1515
private:
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 {
2121
public:
22-
C5() : x(y) {}
22+
C5(unsigned char y) : x(y) {}
2323

2424
private:
2525
std::uint8_t x;
2626
};
2727

28-
template <typename T, T y> class C6 {
28+
class C6 {
2929
public:
30-
C6() : x(y) {}
30+
C6(signed char y) : x(y) {}
3131

3232
private:
3333
std::int8_t x;
@@ -40,69 +40,6 @@ void f2(signed char x) {}
4040
void f9(std::uint8_t x) {}
4141
void 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-
10643
int 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

Comments
 (0)