Skip to content

A3-1-5: change definition of trivial length #633

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

Merged
merged 2 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions change_notes/2024-07-03-fix-fp-611-A3-1-5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `A3-1-5` - `NonTrivialNonTemplateFunctionDefinedInsideClassDefinition.ql`, `TrivialOrTemplateFunctionDefinedOutsideClassDefinition.ql`:
- Fixes #611. Relax definition of trivial length of trivial member function to 10 LOC.
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
| test.cpp:12:7:12:13 | trivial | Non-Trivial or non-template function trivial is defined in the class body of $@. | test.cpp:2:7:2:7 | A | A |
| test.cpp:26:7:26:9 | gcd | Non-Trivial or non-template function gcd is defined in the class body of $@. | test.cpp:2:7:2:7 | A | A |
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
| test.cpp:58:5:58:11 | getB | The trivial member function getB is not defined in the class body of $@. | test.cpp:2:7:2:7 | A | A |
| test.cpp:60:25:60:28 | d | The template member function d is not defined in the class body of $@. | test.cpp:2:7:2:7 | A | A |
| test.cpp:62:5:62:8 | b | The trivial member function b is not defined in the class body of $@. | test.cpp:2:7:2:7 | A | A |
| test.cpp:81:34:81:57 | complexCalculation | The template member function complexCalculation is not defined in the class body of $@. | test.cpp:64:29:64:29 | B<C> | B<C> |
| test.cpp:97:47:97:53 | d | The template member function d is not defined in the class body of $@. | test.cpp:64:29:64:29 | B<C> | B<C> |
| test.cpp:101:27:101:33 | b | The template member function b is not defined in the class body of $@. | test.cpp:64:29:64:29 | B<C> | B<C> |
| test.cpp:106:27:106:36 | getB | The template member function getB is not defined in the class body of $@. | test.cpp:64:29:64:29 | B<C> | B<C> |
| test.cpp:65:5:65:11 | getB | The trivial member function getB is not defined in the class body of $@. | test.cpp:2:7:2:7 | A | A |
| test.cpp:67:25:67:28 | d | The template member function d is not defined in the class body of $@. | test.cpp:2:7:2:7 | A | A |
| test.cpp:69:5:69:8 | b | The trivial member function b is not defined in the class body of $@. | test.cpp:2:7:2:7 | A | A |
| test.cpp:88:34:88:57 | complexCalculation | The template member function complexCalculation is not defined in the class body of $@. | test.cpp:71:29:71:29 | B<C> | B<C> |
| test.cpp:104:47:104:53 | d | The template member function d is not defined in the class body of $@. | test.cpp:71:29:71:29 | B<C> | B<C> |
| test.cpp:108:27:108:33 | b | The template member function b is not defined in the class body of $@. | test.cpp:71:29:71:29 | B<C> | B<C> |
| test.cpp:113:27:113:36 | getB | The template member function getB is not defined in the class body of $@. | test.cpp:71:29:71:29 | B<C> | B<C> |
16 changes: 15 additions & 1 deletion cpp/autosar/test/rules/A3-1-5/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class A {

int getABar() { return 9; }

int trivial() { // NON_COMPLIANT
int not_trivial() { // COMPLIANT - with threshold of 10 loc
;
;
;
Expand All @@ -28,6 +28,13 @@ class A {
return a;
int result = gcd(b, (a % b));
;
;
;
;
;
;
;
;
return result;
}

Expand Down Expand Up @@ -131,5 +138,12 @@ int FooBar::f1(int a, int b) { // COMPLIANT not a trivial function
return a;
int result = FooBar::f1(b, (a % b));
;
;
;
;
;
;
;
;
}
}
3 changes: 1 addition & 2 deletions cpp/common/src/codingstandards/cpp/Class.qll
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ class IntrospectedMemberFunction extends MemberFunction {
}

predicate hasTrivialLength() {
this.getBlock().getNumStmt() <= 3 and
not exists(this.getBlock().getStmt(_).getChildStmt())
this.getBlock().getLocation().getEndLine() - this.getBlock().getLocation().getStartLine() <= 10
}

predicate isSetter() {
Expand Down
Loading