Skip to content

Commit 5ba5f3a

Browse files
authored
Issue 18: exclude uninstantiated templates (#61)
* Fix issue 18: exclude uninstantiated templates
1 parent d09605b commit 5ba5f3a

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- `A7-1-1` - `DeclarationUnmodifiedObjectMissingConstSpecifier.ql`:
2+
- Remove findings in uninstantiated Templates.

cpp/autosar/src/rules/A7-1-1/DeclarationUnmodifiedObjectMissingConstSpecifier.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ where
3535
cond = " points to an object"
3636
else cond = " is used for an object"
3737
) and
38-
not exists(LambdaExpression lc | lc.getACapture().getField() = v)
38+
not exists(LambdaExpression lc | lc.getACapture().getField() = v) and
39+
not v.isFromUninstantiatedTemplate(_)
3940
select v, "Non-constant variable " + v.getName() + cond + " and is not modified."

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,42 @@ class A7_1_1a final {
3939
m_ = a.m;
4040
}
4141
void Call() {
42-
[this]() { std::cout << m_ << '\n'; }(); // COMPLIANT ignore lambdas
42+
// ignore lambdas
43+
[this]() { std::cout << m_ << '\n'; }(); // COMPLIANT
4344
}
4445

4546
private:
4647
std::string m_;
4748
};
49+
50+
template <typename T> class A7_1_1b final {
51+
public:
52+
explicit A7_1_1b(int i) noexcept {
53+
t_.Init(i);
54+
} // t_ is modified here by Init
55+
private:
56+
// ignore uninstantiated templates
57+
T t_; // COMPLIANT
58+
};
59+
60+
class A7_1_1bHelper {
61+
public:
62+
void Init(int i) {}
63+
};
64+
65+
class Issue18 {
66+
public:
67+
template <typename T> void F(const T &s) {
68+
// ignore uninstantiated templates
69+
std::ostream ostr; // COMPLIANT
70+
ostr << s; // <= Modified here
71+
return;
72+
}
73+
};
74+
75+
/// main
76+
int main(int, char **) noexcept {
77+
new A7_1_1b<A7_1_1bHelper>(0);
78+
79+
(new Issue18)->F(0);
80+
}

0 commit comments

Comments
 (0)