Skip to content

Commit 35ef53b

Browse files
authored
Merge pull request #266 from github/jeongsoolee09/False-positives-1
Address False Positives for Autosar
2 parents 5af66d1 + 62c9825 commit 35ef53b

File tree

11 files changed

+90
-24
lines changed

11 files changed

+90
-24
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `A15-4-4` - `MissingNoExcept.ql`
2+
- Exclude call operators embedded in a lambda expression from functions to be declared `noexcept` or `noexcept(false)`.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `A2-7-3` - `UndocumentedUserDefinedType.ql`:
2+
- Exclude lambda functions from program elements to be documented.

cpp/autosar/src/rules/A15-4-4/MissingNoExcept.ql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,7 @@ where
3131
// Not compiler generated
3232
not f.isCompilerGenerated() and
3333
// The function is defined in this database
34-
f.hasDefinition()
34+
f.hasDefinition() and
35+
// This function is not an overriden call operator of a lambda expression
36+
not exists(LambdaExpression lambda | lambda.getLambdaFunction() = f)
3537
select f, "Function " + f.getName() + " could be declared noexcept(true)."

cpp/autosar/src/rules/A2-7-3/UndocumentedUserDefinedType.ql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ class DocumentableDeclaration extends Declaration {
3636
// Exclude instantiated template functions, which cannot reasonably be documented.
3737
not this.(Function).isFromTemplateInstantiation(_) and
3838
// Exclude anonymous lambda functions.
39-
not exists(LambdaExpression lc |
40-
lc.getLambdaFunction() = this and not lc.getEnclosingElement() instanceof Initializer
41-
)
39+
not exists(LambdaExpression lc | lc.getLambdaFunction() = this)
4240
or
4341
this instanceof MemberVariable and
4442
declarationType = "member variable" and
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
| test.cpp:22:10:22:11 | 0 | Definition of $@ is unused. | test.cpp:22:7:22:7 | y | y |
2-
| test.cpp:25:3:25:5 | ... ++ | Definition of $@ is unused. | test.cpp:24:7:24:7 | z | z |
3-
| test.cpp:42:3:42:7 | ... = ... | Definition of $@ is unused. | test.cpp:20:41:20:41 | p | p |
4-
| test.cpp:44:10:44:11 | 0 | Definition of $@ is unused. | test.cpp:44:7:44:8 | l3 | l3 |
5-
| test.cpp:45:13:45:22 | new | Definition of $@ is unused. | test.cpp:45:8:45:9 | l4 | l4 |
6-
| test.cpp:48:8:48:8 | {...} | Definition of $@ is unused. | test.cpp:48:5:48:6 | a2 | a2 |
7-
| test.cpp:49:11:49:15 | new | Definition of $@ is unused. | test.cpp:49:6:49:7 | a3 | a3 |
8-
| test.cpp:50:11:50:17 | new | Definition of $@ is unused. | test.cpp:50:6:50:7 | a4 | a4 |
9-
| test.cpp:51:11:51:17 | 0 | Definition of $@ is unused. | test.cpp:51:6:51:7 | a5 | a5 |
10-
| test.cpp:55:3:55:10 | ... = ... | Definition of $@ is unused. | test.cpp:52:5:52:6 | a6 | a6 |
11-
| test.cpp:60:11:60:15 | new | Definition of $@ is unused. | test.cpp:60:6:60:7 | b3 | b3 |
12-
| test.cpp:61:11:61:17 | new | Definition of $@ is unused. | test.cpp:61:6:61:7 | b4 | b4 |
13-
| test.cpp:62:11:62:17 | 0 | Definition of $@ is unused. | test.cpp:62:6:62:7 | b5 | b5 |
14-
| test.cpp:70:11:70:17 | 0 | Definition of $@ is unused. | test.cpp:70:6:70:7 | c5 | c5 |
1+
| test.cpp:55:10:55:11 | 0 | Definition of $@ is unused. | test.cpp:55:7:55:7 | y | y |
2+
| test.cpp:58:3:58:5 | ... ++ | Definition of $@ is unused. | test.cpp:57:7:57:7 | z | z |
3+
| test.cpp:75:3:75:7 | ... = ... | Definition of $@ is unused. | test.cpp:53:41:53:41 | p | p |
4+
| test.cpp:77:10:77:11 | 0 | Definition of $@ is unused. | test.cpp:77:7:77:8 | l3 | l3 |
5+
| test.cpp:78:13:78:22 | new | Definition of $@ is unused. | test.cpp:78:8:78:9 | l4 | l4 |
6+
| test.cpp:81:8:81:8 | {...} | Definition of $@ is unused. | test.cpp:81:5:81:6 | a2 | a2 |
7+
| test.cpp:82:11:82:15 | new | Definition of $@ is unused. | test.cpp:82:6:82:7 | a3 | a3 |
8+
| test.cpp:83:11:83:17 | new | Definition of $@ is unused. | test.cpp:83:6:83:7 | a4 | a4 |
9+
| test.cpp:84:11:84:17 | 0 | Definition of $@ is unused. | test.cpp:84:6:84:7 | a5 | a5 |
10+
| test.cpp:88:3:88:10 | ... = ... | Definition of $@ is unused. | test.cpp:85:5:85:6 | a6 | a6 |
11+
| test.cpp:93:11:93:15 | new | Definition of $@ is unused. | test.cpp:93:6:93:7 | b3 | b3 |
12+
| test.cpp:94:11:94:17 | new | Definition of $@ is unused. | test.cpp:94:6:94:7 | b4 | b4 |
13+
| test.cpp:95:11:95:17 | 0 | Definition of $@ is unused. | test.cpp:95:6:95:7 | b5 | b5 |
14+
| test.cpp:103:11:103:17 | 0 | Definition of $@ is unused. | test.cpp:103:6:103:7 | c5 | c5 |

cpp/autosar/test/rules/A0-1-1/options.clang

Lines changed: 0 additions & 1 deletion
This file was deleted.

cpp/autosar/test/rules/A0-1-1/test.cpp

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,39 @@ struct C {
1717
int m;
1818
};
1919

20+
void sample1(int x){};
21+
void sample2(int y){};
22+
23+
static void foo(B &b) noexcept {
24+
b.g();
25+
B bar{};
26+
bar.g();
27+
B b2 = B();
28+
auto b3 = &b2;
29+
b3->g();
30+
B &b4 = b;
31+
b4.g();
32+
auto &b5 = *new B();
33+
b5.g();
34+
/* Below causes a compile error (non-const reference when initialized should
35+
* hold an lvalue)
36+
*/
37+
// auto &b6 = new B();
38+
// b6.g();
39+
}
40+
41+
template <typename T> void test() {
42+
T t;
43+
t.g();
44+
}
45+
46+
template <typename T> void call_test() {
47+
// call it with type parameter B to trigger indexing
48+
test<T>();
49+
}
50+
51+
void call_call_test() { call_test<B>(); }
52+
2053
int test_useless_assignment(int &x, int p) {
2154
x = 0; // COMPLIANT - x is a reference parameter, so is visible by the caller
2255
int y = 0; // NON_COMPLIANT - never used
@@ -49,7 +82,7 @@ int test_useless_assignment(int &x, int p) {
4982
A *a3 = new A; // NON_COMPLIANT - POD class, no constructor/destructor
5083
A *a4 = new A(); // NON_COMPLIANT - POD class, no constructor/destructor
5184
A *a5 = nullptr; // NON_COMPLIANT - null never read
52-
A a6{}; // COMPLIANT - `m` assigned below
85+
A a6{}; // COMPLIANT - `f` assigned below
5386
a6.f = 2; // COMPLIANT - we don't track the fields here, but we do track `a6`,
5487
// so we'd consider this used by the assignment below
5588
a6.f = 1; // NON_COMPLIANT - assignment into `f`, but `a6` is not used
@@ -69,5 +102,14 @@ int test_useless_assignment(int &x, int p) {
69102
C *c4 = new C(); // COMPLIANT - this will call a constructor??
70103
C *c5 = nullptr; // NON_COMPLIANT - null never read
71104

105+
A a7{1, 2}; // COMPLIANT - used in the `sample1` call below
106+
sample1(a7.f + a7.f2); // COMPLIANT - object access is a valid use
107+
108+
// A *a8; // COMPLIANT - value not given at declaration
109+
// a8 = &a7;
110+
// sample2(a8->f); // COMPLIANT - object access is a valid use
111+
72112
return y;
73113
}
114+
115+
int main() { return 0; }

cpp/autosar/test/rules/A15-4-4/test.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,10 @@ void test_indirect_throw() { // COMPLIANT - throws an exception indirectly
2424
class A {
2525
public:
2626
A() = delete; // COMPLIANT - deleted functions imply `noexcept(true)`.
27-
};
27+
};
28+
29+
/* Added for testing FP of embedded operator inside lambdas being reported */
30+
void lambda_example() noexcept {
31+
auto with_capture = [=]() {};
32+
auto empty_capture = []() {};
33+
}

cpp/autosar/test/rules/A2-7-3/UndocumentedUserDefinedType.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@
66
| test.cpp:78:6:78:6 | declaration of d | Declaration entry for function d is missing documentation. |
77
| test.cpp:81:6:81:6 | definition of e | Declaration entry for function e is missing documentation. |
88
| test.cpp:88:1:88:30 | definition of message_to_string_undocumented | Declaration entry for function message_to_string_undocumented is missing documentation. |
9-
| test.cpp:113:14:113:14 | definition of operator() | Declaration entry for function operator() is missing documentation. |
109
| test.cpp:160:21:160:24 | definition of kBar | Declaration entry for member variable kBar is missing documentation. |

cpp/autosar/test/rules/A2-7-3/test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ std::string template_function_test() { // COMPLIANT
110110

111111
/// @brief function assigned_lambda_test.
112112
int assigned_lambda_test() {
113-
auto l = [](int x, int y) { return x + y; }; // NON_COMPLIANT
113+
auto l = [](int x, int y) { return x + y; }; // COMPLIANT: We exclude lambdas.
114114
return l(2, 3);
115115
}
116116

@@ -160,4 +160,4 @@ template <typename T> class A2_7_3 final {
160160
const std::string kBar{"bar"}; // NON_COMPLIANT
161161
};
162162
/// @brief This is the instantiateA2_7_3 documentation
163-
void instantiateA2_7_3() { A2_7_3<int> instance; }
163+
void instantiateA2_7_3() { A2_7_3<int> instance; }

cpp/autosar/test/rules/A5-2-6/test.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,20 @@ void f2(int p1, int p2) {
1515
if ((p1 > 0) || (p2 > 0)) { // COMPLIANT
1616
f1();
1717
}
18+
19+
struct Sample {
20+
int x;
21+
} sample;
22+
23+
if ((p1 > 0) ||
24+
sample.x) { // COMPLIANT: struct member accessors (.) are excluded
25+
f1();
26+
}
27+
28+
Sample *sample_ptr = &sample;
29+
30+
if ((p1 > 0) || sample_ptr->x) { // COMPLIANT: struct member accessors with
31+
// dereference (->) are excluded
32+
f1();
33+
}
1834
}

0 commit comments

Comments
 (0)