Skip to content

Commit 562c7be

Browse files
committed
Add two more cases
1 parent 999e870 commit 562c7be

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

cpp/misra/test/rules/RULE-9-5-1/test.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ void g1(int *x) {} // Function that takes a non-const integer pointer
66
void f2(const int &x) {} // Function that takes a non-const integer reference
77
void g2(const int *x) {} // Function that takes a non-const integer pointer
88

9+
int h1() { return 1; }
10+
constexpr int h2() { return 1; }
11+
912
int main() {
1013
int j = 5;
1114
int k = 10;
@@ -120,24 +123,20 @@ int main() {
120123
*(true ? &l : &n) += 1;
121124
}
122125

123-
std::string hello1 = "hello";
124-
std::string_view hello2{"hello"};
125-
126-
for (int i = 0; i < hello1.size();
126+
for (int i = 0; i < h1();
127127
i++) { // NON_COMPLIANT: The loop bound is not a constant expression
128128
}
129129

130-
for (int i = 0; i < hello2.size();
130+
for (int i = 0; i < h2();
131131
i++) { // COMPLIANT: The loop bound is a constant expression
132132
}
133133

134-
for (int i = 0; i < j; i += hello1.size()) { // NON_COMPLIANT: The loop step
135-
// is not a constant expression
134+
for (int i = 0; i < j;
135+
i += h1()) { // NON_COMPLIANT: The loop step is not a constant expression
136136
}
137137

138138
for (int i = 0; i < j;
139-
i +=
140-
hello2.size()) { // COMPLIANT: The loop step is a constant expression
139+
i += h2()) { // COMPLIANT: The loop step is a constant expression
141140
}
142141

143142
/* ========== 6. Existence of pointers to the loop counter, loop bound, and

0 commit comments

Comments
 (0)