Skip to content

Commit f0e3c45

Browse files
committed
A7-1-2: Refactor test case to reflect rule intention
Change the test case related to constexpr functions to highlight expected behaviour for local variables.
1 parent 0ba3359 commit f0e3c45

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

cpp/autosar/test/rules/A7-1-2/VariableMissingConstexpr.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
| test.cpp:44:16:44:17 | lc | Variable 'lc' could be marked 'constexpr'. |
99
| test.cpp:45:17:45:19 | lc2 | Variable 'lc2' could be marked 'constexpr'. |
1010
| test.cpp:55:7:55:8 | m2 | Variable 'm2' could be marked 'constexpr' and static. |
11+
| test.cpp:65:7:65:8 | x2 | Variable 'x2' could be marked 'constexpr'. |
12+
| test.cpp:66:13:66:14 | x3 | Variable 'x3' could be marked 'constexpr'. |
1113
| test.cpp:130:7:130:8 | m1 | Variable 'm1' could be marked 'constexpr' and static. |
1214
| test.cpp:141:7:141:8 | m1 | Variable 'm1' could be marked 'constexpr' and static. |
1315
| test.cpp:221:7:221:8 | l1 | Variable 'l1' could be marked 'constexpr'. |

cpp/autosar/test/rules/A7-1-2/test.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,16 @@ class MemberConstExpr {
5656
int m3 = 0; // COMPLIANT - can be set by constructor
5757
};
5858

59-
int h1(int x, int y) { // NON_COMPLIANT
60-
return x + y;
61-
}
59+
int h1(int x, int y) { return x + y; }
6260

63-
constexpr int h1_correct(int x, int y) { // COMPLIANT
64-
return x + y;
65-
}
61+
constexpr int h1_const(int x, int y) { return x + y; }
6662

67-
int h2(int x) { return h1(x, 1) + 1; } // NON_COMPLIANT
68-
constexpr int h2_correct(int x) { return h1_correct(x, 1) + 1; } // COMPLIANT
63+
int h2() {
64+
int x1 = h1(1, 1); // COMPLIANT
65+
int x2 = h1_const(1, 1); // NON_COMPLIANT
66+
const int x3 = h1_const(1, 1); // NON_COMPLIANT
67+
constexpr int x4 = h1_const(1, 1); // COMPLIANT
68+
}
6969

7070
int h3(int x) { // COMPLIANT - uses goto, so can't be constexpr
7171
if (x) {

0 commit comments

Comments
 (0)