add warning for literal passed to non-const parameter
Adds a new warning to warn users when they pass an array/string literal to a non-const qualified parameter. ``` f1(arr[]) { new a = arr[0]; #pragma unused a } f2(arr[5]) { new a = arr[0]; #pragma unused a } f3(const arr[]) { new a = arr[0]; #pragma unused a } f4(const arr[5]) { new a = arr[0]; #pragma unused a } main () { f1("test"); f2("test"); f3("test"); f4("test"); new arr[5]; f1(arr); f2(arr); f3(arr); f4(arr); f1(arr[0]); //f2(arr[0]); - array size must match f3(arr[0]); //f4(arr[0]); - array size must match } ``` ``` test.pwn(1) : warning 214: possibly a "const" array argument was intended: "arr" test.pwn(6) : warning 214: possibly a "const" array argument was intended: "arr" test.pwn(20) : warning 239: literal array/string passed to a non-const parameter test.pwn(21) : warning 239: literal array/string passed to a non-const parameter ```
This commit is contained in:
parent
29669858b3
commit
c363c5b1de
@ -2214,10 +2214,13 @@ static int nesting=0;
|
||||
if (lval.sym==NULL || lval.ident==iARRAYCELL) {
|
||||
if (arg[argidx].numdim!=1) {
|
||||
error(48); /* array dimensions must match */
|
||||
} else if (arg[argidx].dim[0]!=0) {
|
||||
} else {
|
||||
if (lval.sym==NULL && (arg[argidx].usage & uCONST)==0)
|
||||
error(239);
|
||||
if (arg[argidx].dim[0]!=0) {
|
||||
assert(arg[argidx].dim[0]>0);
|
||||
if (lval.ident==iARRAYCELL) {
|
||||
error(47); /* array sizes must match */
|
||||
error(7); /* array sizes must match */
|
||||
} else {
|
||||
assert(lval.constval!=0); /* literal array must have a size */
|
||||
/* A literal array must have exactly the same size as the
|
||||
@ -2229,6 +2232,7 @@ static int nesting=0;
|
||||
error(47); /* array sizes must match */
|
||||
} /* if */
|
||||
} /* if */
|
||||
} /* if */
|
||||
if (lval.ident!=iARRAYCELL || lval.constval > 0) {
|
||||
/* save array size, for default values with uSIZEOF flag */
|
||||
cell array_sz=lval.constval;
|
||||
|
@ -192,7 +192,8 @@ static char *warnmsg[] = {
|
||||
/*235*/ "public function lacks forward declaration (symbol \"%s\")\n",
|
||||
/*236*/ "unknown parameter in substitution (incorrect #define pattern)\n",
|
||||
/*237*/ "user warning: %s\n",
|
||||
/*238*/ "meaningless combination of class specifiers (%s)\n"
|
||||
/*238*/ "meaningless combination of class specifiers (%s)\n",
|
||||
/*239*/ "literal array/string passed to a non-const parameter\n"
|
||||
};
|
||||
|
||||
#define NUM_WARNINGS (sizeof warnmsg / sizeof warnmsg[0])
|
||||
|
Loading…
x
Reference in New Issue
Block a user