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
66void f2 (const int &x) {} // Function that takes a non-const integer reference
77void 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+
912int 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
You can’t perform that action at this time.
0 commit comments