Skip to content

Commit 01e89f3

Browse files
committed
Add two more test cases to make sure passed-by-reference function arguments don't conflict with the new warnings
1 parent d9f500b commit 01e89f3

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{
22
'test_type': 'output_check',
33
'errors': """
4-
warning_250_251.pwn(12) : warning 250: variable "n" used in loop condition not modified in loop body
5-
warning_250_251.pwn(13) : warning 250: variable "i" used in loop condition not modified in loop body
6-
warning_250_251.pwn(31) : warning 250: variable "n" used in loop condition not modified in loop body
7-
warning_250_251.pwn(32) : warning 250: variable "i" used in loop condition not modified in loop body
8-
warning_250_251.pwn(46) : warning 251: none of the variables used in loop condition are modified in loop body
9-
warning_250_251.pwn(47) : warning 251: none of the variables used in loop condition are modified in loop body
4+
warning_250_251.pwn(19) : warning 250: variable "n" used in loop condition not modified in loop body
5+
warning_250_251.pwn(20) : warning 250: variable "i" used in loop condition not modified in loop body
6+
warning_250_251.pwn(38) : warning 250: variable "n" used in loop condition not modified in loop body
7+
warning_250_251.pwn(39) : warning 250: variable "i" used in loop condition not modified in loop body
8+
warning_250_251.pwn(53) : warning 251: none of the variables used in loop condition are modified in loop body
9+
warning_250_251.pwn(54) : warning 251: none of the variables used in loop condition are modified in loop body
10+
warning_250_251.pwn(111) : warning 250: variable "n" used in loop condition not modified in loop body
11+
warning_250_251.pwn(112) : warning 251: none of the variables used in loop condition are modified in loop body
1012
"""
1113
}

source/compiler/tests/warning_250_251.pwn

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,21 @@
33

44
new glbvar = 0;
55

6+
stock UseVarByRef(&arg)
7+
return arg;
8+
9+
#pragma warning disable 238 // "meaningless combination of class specifiers (const reference)"
10+
stock UseVarByConstRef(const &arg)
11+
return arg;
12+
613
main()
714
{
815
new n = 0, m = 10;
916
static st = 0;
1017

1118
// Case 1: Variable is used inside a loop condition without being modified.
12-
while (n < 10) {} // warning 250: variable used in loop condition not modified in loop body (symbol "n")
13-
for (new i = 0, j = 0; i < 10; ++j) {} // warning 250: variable used in loop condition not modified in loop body (symbol "i")
19+
while (n < 10) {} // warning 250: variable "n" used in loop condition not modified in loop body
20+
for (new i = 0, j = 0; i < 10; ++j) {} // warning 250: variable "i" used in loop condition not modified in loop body
1421

1522
// Case 2: Variable is used inside a loop condition and modified in the loop body.
1623
while (n != 0) { n++; }
@@ -28,8 +35,8 @@ main()
2835

2936
// Case 5: Same variable is used inside a loop condition more than once
3037
// and it's not modified.
31-
while (n == 0 || n < 10) {} // warning 250: variable used in loop condition not modified in loop body (symbol "n")
32-
for (new i = 0; i == 0 || i < 10; ) {} // warning 250: variable used in loop condition not modified in loop body (symbol "i")
38+
while (n == 0 || n < 10) {} // warning 250: variable "n" used in loop condition not modified in loop body
39+
for (new i = 0; i == 0 || i < 10; ) {} // warning 250: variable "i" used in loop condition not modified in loop body
3340

3441
// Case 6: Same variable is used inside a loop condition more than once,
3542
// but it's modified.
@@ -91,5 +98,17 @@ main()
9198
// way to track this.
9299
while (n < glbvar) {}
93100
for (new i = 0; i < glbvar; ) {}
101+
102+
// Case 13: Warnings 250 and 251 shouldn't trigger when the loop counter
103+
// variable is passed to a function by reference.
104+
while (n < 10) UseVarByRef(n);
105+
while (n < m) UseVarByRef(n);
106+
107+
// Case 14: While const references for single function arguments are
108+
// meaningless and there's warning 238 for this, such references still
109+
// shouldn't affect warnings 250 and 251, as variables passed by const
110+
// references aren't counted as modified.
111+
while (n < 10) UseVarByConstRef(n); // warning 250: variable "n" used in loop condition not modified in loop body
112+
while (n < m) UseVarByConstRef(n); // warning 251: none of the variables used in loop condition are modified in loop body
94113
}
95114

0 commit comments

Comments
 (0)