File tree Expand file tree Collapse file tree 1 file changed +8
-9
lines changed
cpp/misra/test/rules/RULE-9-5-1 Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,9 @@ void g1(int *x) {} // Function that takes a non-const integer pointer
6
6
void f2 (const int &x) {} // Function that takes a non-const integer reference
7
7
void g2 (const int *x) {} // Function that takes a non-const integer pointer
8
8
9
+ int h1 () { return 1 ; }
10
+ constexpr int h2 () { return 1 ; }
11
+
9
12
int main () {
10
13
int j = 5 ;
11
14
int k = 10 ;
@@ -120,24 +123,20 @@ int main() {
120
123
*(true ? &l : &n) += 1 ;
121
124
}
122
125
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 ();
127
127
i++) { // NON_COMPLIANT: The loop bound is not a constant expression
128
128
}
129
129
130
- for (int i = 0 ; i < hello2. size ();
130
+ for (int i = 0 ; i < h2 ();
131
131
i++) { // COMPLIANT: The loop bound is a constant expression
132
132
}
133
133
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
136
136
}
137
137
138
138
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
141
140
}
142
141
143
142
/* ========== 6. Existence of pointers to the loop counter, loop bound, and
You can’t perform that action at this time.
0 commit comments