From e137b1c4dc75f7aadf2c35a0360244edea99d453 Mon Sep 17 00:00:00 2001 From: Stanislav Gromov Date: Sun, 31 Jan 2021 18:02:32 +0700 Subject: [PATCH] Add two more test cases to make sure passed-by-reference function arguments don't conflict with the new warnings --- source/compiler/tests/warning_250_251.meta | 14 ++++++----- source/compiler/tests/warning_250_251.pwn | 27 ++++++++++++++++++---- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/source/compiler/tests/warning_250_251.meta b/source/compiler/tests/warning_250_251.meta index fa8369f..57a6b24 100644 --- a/source/compiler/tests/warning_250_251.meta +++ b/source/compiler/tests/warning_250_251.meta @@ -1,11 +1,13 @@ { 'test_type': 'output_check', 'errors': """ -warning_250_251.pwn(12) : warning 250: variable "n" used in loop condition not modified in loop body -warning_250_251.pwn(13) : warning 250: variable "i" used in loop condition not modified in loop body -warning_250_251.pwn(31) : warning 250: variable "n" used in loop condition not modified in loop body -warning_250_251.pwn(32) : warning 250: variable "i" used in loop condition not modified in loop body -warning_250_251.pwn(46) : warning 251: none of the variables used in loop condition are modified in loop body -warning_250_251.pwn(47) : warning 251: none of the variables used in loop condition are modified in loop body +warning_250_251.pwn(19) : warning 250: variable "n" used in loop condition not modified in loop body +warning_250_251.pwn(20) : warning 250: variable "i" used in loop condition not modified in loop body +warning_250_251.pwn(38) : warning 250: variable "n" used in loop condition not modified in loop body +warning_250_251.pwn(39) : warning 250: variable "i" used in loop condition not modified in loop body +warning_250_251.pwn(53) : warning 251: none of the variables used in loop condition are modified in loop body +warning_250_251.pwn(54) : warning 251: none of the variables used in loop condition are modified in loop body +warning_250_251.pwn(111) : warning 250: variable "n" used in loop condition not modified in loop body +warning_250_251.pwn(112) : warning 251: none of the variables used in loop condition are modified in loop body """ } diff --git a/source/compiler/tests/warning_250_251.pwn b/source/compiler/tests/warning_250_251.pwn index 4eb83fb..9cf76b7 100644 --- a/source/compiler/tests/warning_250_251.pwn +++ b/source/compiler/tests/warning_250_251.pwn @@ -3,14 +3,21 @@ new glbvar = 0; +stock UseVarByRef(&arg) + return arg; + +#pragma warning disable 238 // "meaningless combination of class specifiers (const reference)" +stock UseVarByConstRef(const &arg) + return arg; + main() { new n = 0, m = 10; static st = 0; // Case 1: Variable is used inside a loop condition without being modified. - while (n < 10) {} // warning 250: variable used in loop condition not modified in loop body (symbol "n") - for (new i = 0, j = 0; i < 10; ++j) {} // warning 250: variable used in loop condition not modified in loop body (symbol "i") + while (n < 10) {} // warning 250: variable "n" used in loop condition not modified in loop body + for (new i = 0, j = 0; i < 10; ++j) {} // warning 250: variable "i" used in loop condition not modified in loop body // Case 2: Variable is used inside a loop condition and modified in the loop body. while (n != 0) { n++; } @@ -28,8 +35,8 @@ main() // Case 5: Same variable is used inside a loop condition more than once // and it's not modified. - while (n == 0 || n < 10) {} // warning 250: variable used in loop condition not modified in loop body (symbol "n") - for (new i = 0; i == 0 || i < 10; ) {} // warning 250: variable used in loop condition not modified in loop body (symbol "i") + while (n == 0 || n < 10) {} // warning 250: variable "n" used in loop condition not modified in loop body + for (new i = 0; i == 0 || i < 10; ) {} // warning 250: variable "i" used in loop condition not modified in loop body // Case 6: Same variable is used inside a loop condition more than once, // but it's modified. @@ -91,5 +98,17 @@ main() // way to track this. while (n < glbvar) {} for (new i = 0; i < glbvar; ) {} + + // Case 13: Warnings 250 and 251 shouldn't trigger when the loop counter + // variable is passed to a function by reference. + while (n < 10) UseVarByRef(n); + while (n < m) UseVarByRef(n); + + // Case 14: While const references for single function arguments are + // meaningless and there's warning 238 for this, such references still + // shouldn't affect warnings 250 and 251, as variables passed by const + // references aren't counted as modified. + while (n < 10) UseVarByConstRef(n); // warning 250: variable "n" used in loop condition not modified in loop body + while (n < m) UseVarByConstRef(n); // warning 251: none of the variables used in loop condition are modified in loop body }