Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A3-1-5: Remove extraneous cases and handle template instantiations #610

Merged
merged 11 commits into from
Jan 13, 2025

This file was deleted.

This file was deleted.

This file was deleted.

59 changes: 51 additions & 8 deletions cpp/autosar/test/rules/A3-1-5/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class A {

lcartey marked this conversation as resolved.
Show resolved Hide resolved
int complexCalculation();

knewbury01 marked this conversation as resolved.
Show resolved Hide resolved
int gcd(int a, int b) {
int gcd(int a, int b) { // NON_COMPLIANT
if (b == 0)
return a;
int result = gcd(b, (a % b));
Expand Down Expand Up @@ -55,11 +55,11 @@ inline int A::complexCalculation() { // COMPLIANT
return 1;
}

int A::getB() { return 1; } // NON_COMPLIANT
int A::getB() { return 1; } // COMPLIANT

template <typename T> T A::d(T t) { return t; } // NON_COMPLIANT
template <typename T> T A::d(T t) { return t; } // COMPLIANT

int A::b() { return 3; } // NON_COMPLIANT
int A::b() { return 3; } // COMPLIANT

template <typename C> class B {
public:
Expand All @@ -76,9 +76,30 @@ template <typename C> class B {
template <typename T> T d(T t);

int complexCalculation();

int complexCalculation2() { // COMPLIANT - template
;
;
;
;
;
;
;
;
;
;
;
;
return 1;
}
};

template <typename C> inline int B<C>::complexCalculation() { // NON_COMPLIANT
void test_B() {
B<int> b;
b.complexCalculation2();
}

template <typename C> inline int B<C>::complexCalculation() { // COMPLIANT
;
;
;
Expand All @@ -94,16 +115,16 @@ template <typename C> inline int B<C>::complexCalculation() { // NON_COMPLIANT
return 1;
}

template <typename C> template <typename T> T B<C>::d(T t) { // NON_COMPLIANT
template <typename C> template <typename T> T B<C>::d(T t) { // COMPLIANT
return t;
}

template <typename C> int B<C>::b() { // NON_COMPLIANT
template <typename C> int B<C>::b() { // COMPLIANT
C c;
return 3;
}

template <typename C> int B<C>::getB() { return 3; } // NON_COMPLIANT
template <typename C> int B<C>::getB() { return 3; } // COMPLIANT

template <typename T> class Foo {
public:
Expand All @@ -121,8 +142,30 @@ class FooBar {
public:
~FooBar();
int f1(int a, int b);

template <typename C> int complexCalculation() { // COMPLIANT - template
;
;
;
;
;
;
;
;
;
;
;
;
return 1;
}
};

void test_FooBar() {
FooBar foobar;
foobar.complexCalculation<int>();
}


FooBar::~FooBar() {} // COMPLIANT want to ignore pImpl uses of destructors

int FooBar::f1(int a, int b) { // COMPLIANT not a trivial function
Expand Down
5 changes: 4 additions & 1 deletion cpp/common/src/codingstandards/cpp/Class.qll
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ class TrivialMemberFunction extends IntrospectedMemberFunction {
* class.
*/
class TemplateOrTemplateClassMemberFunction extends MemberFunction {
TemplateOrTemplateClassMemberFunction() { isFromUninstantiatedTemplate(_) }
TemplateOrTemplateClassMemberFunction() {
isFromUninstantiatedTemplate(_) or
isFromTemplateInstantiation(_)
lcartey marked this conversation as resolved.
Show resolved Hide resolved
}
}

/**
Expand Down
Loading