File tree Expand file tree Collapse file tree 2 files changed +58
-0
lines changed
cpp/autosar/test/rules/M6-5-3 Expand file tree Collapse file tree 2 files changed +58
-0
lines changed Original file line number Diff line number Diff line change 22| test.cpp:25:35:25:35 | x | Loop counters should not be modified within a statement in a for loop. |
33| test.cpp:36:5:36:5 | x | Loop counters should not be modified within a statement in a for loop. |
44| test.cpp:43:9:43:9 | i | Loop counters should not be modified within a statement in a for loop. |
5+ | test.cpp:99:15:99:15 | i | Loop counters should not be modified within a statement in a for loop. |
Original file line number Diff line number Diff line change @@ -43,3 +43,60 @@ void test_loop_counter_mod_in_side_effect() {
4343 inc (i); // NON_COMPLIANT - modifies `i`
4444 }
4545}
46+
47+ void test_loop_counter_reference_mod_in_condition () {
48+ auto loop = [](int & i){
49+ for (; (i++ < 10 ); i++) { // NON_COMPLIANT
50+ }
51+ };
52+ int i = 0 ;
53+ loop (i);
54+ }
55+
56+ void test_loop_counter_reference_mod () {
57+ auto loop = [](int & i){
58+ for (; i < 10 ; i++) { // COMPLIANT
59+ }
60+ };
61+ int i = 0 ;
62+ loop (i);
63+ }
64+
65+ void test_loop_const_reference () {
66+ auto loop = []([[maybe_unused]] int const & i){
67+ for (int i = 0 ; i < 10 ; i++) { // COMPLIANT
68+ }
69+ };
70+ int i = 0 ;
71+ loop (i);
72+ }
73+
74+ void test_loop_counter_reference_mod_in_statement () {
75+ auto loop = [](int & i){
76+ for (; (i < 10 ); i++) {
77+ i++; // NON_COMPLIANT
78+ }
79+ };
80+ int i = 0 ;
81+ loop (i);
82+ }
83+
84+ int const_reference (int const & i) {
85+ return i;
86+ }
87+
88+ int reference (int & i) {
89+ return i;
90+ }
91+
92+ int copy (int i) {
93+ return i;
94+ }
95+
96+ void test_pass_argument_by () {
97+ for (int i = 0 ; i < 10 ; i++) {
98+ const_reference (i); // COMPLIANT
99+ reference (i); // NON_COMPLIANT
100+ copy (i); // COMPLIANT
101+ }
102+ }
You can’t perform that action at this time.
0 commit comments