diff --git a/change_notes/2022-08-17-fix-reported-fp-for-a7-1-1.md b/change_notes/2022-08-17-fix-reported-fp-for-a7-1-1.md new file mode 100644 index 0000000000..57584a19c5 --- /dev/null +++ b/change_notes/2022-08-17-fix-reported-fp-for-a7-1-1.md @@ -0,0 +1,2 @@ + - `A7-1-1` - `DeclarationUnmodifiedObjectMissingConstSpecifier.ql`: + - Remove findings in uninstantiated Templates. \ No newline at end of file diff --git a/cpp/autosar/src/rules/A7-1-1/DeclarationUnmodifiedObjectMissingConstSpecifier.ql b/cpp/autosar/src/rules/A7-1-1/DeclarationUnmodifiedObjectMissingConstSpecifier.ql index f421cc7eb5..d85a638530 100644 --- a/cpp/autosar/src/rules/A7-1-1/DeclarationUnmodifiedObjectMissingConstSpecifier.ql +++ b/cpp/autosar/src/rules/A7-1-1/DeclarationUnmodifiedObjectMissingConstSpecifier.ql @@ -35,5 +35,6 @@ where cond = " points to an object" else cond = " is used for an object" ) and - not exists(LambdaExpression lc | lc.getACapture().getField() = v) + not exists(LambdaExpression lc | lc.getACapture().getField() = v) and + not v.isFromUninstantiatedTemplate(_) select v, "Non-constant variable " + v.getName() + cond + " and is not modified." diff --git a/cpp/autosar/test/rules/A7-1-1/test.cpp b/cpp/autosar/test/rules/A7-1-1/test.cpp index fcfd8c618f..4ee62ed013 100644 --- a/cpp/autosar/test/rules/A7-1-1/test.cpp +++ b/cpp/autosar/test/rules/A7-1-1/test.cpp @@ -39,9 +39,42 @@ class A7_1_1a final { m_ = a.m; } void Call() { - [this]() { std::cout << m_ << '\n'; }(); // COMPLIANT ignore lambdas + // ignore lambdas + [this]() { std::cout << m_ << '\n'; }(); // COMPLIANT } private: std::string m_; }; + +template class A7_1_1b final { +public: + explicit A7_1_1b(int i) noexcept { + t_.Init(i); + } // t_ is modified here by Init +private: + // ignore uninstantiated templates + T t_; // COMPLIANT +}; + +class A7_1_1bHelper { +public: + void Init(int i) {} +}; + +class Issue18 { +public: + template void F(const T &s) { + // ignore uninstantiated templates + std::ostream ostr; // COMPLIANT + ostr << s; // <= Modified here + return; + } +}; + +/// main +int main(int, char **) noexcept { + new A7_1_1b(0); + + (new Issue18)->F(0); +} \ No newline at end of file