Skip to content
Merged

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 {

int complexCalculation();

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(_)
}
}

/**
Expand Down