Bug Report: False positive warning 214 on mutable output buffer parameter
Description
The compiler emits warning 214: possibly a "const" array argument was intended on a function parameter that is intentionally mutable — it is used as an output buffer written to by format(). The warning is a false positive because the parameter is never intended to be read-only.
Compiler version
pawncc — compiler (version 3.10.10)
Minimal reproducible example
stock GetPlayerOrgRankName(playerid, dest[], len = sizeof(dest))
{
if(!IsPlayerInOrg(playerid))
{
format(dest, len, "Sin organizacion");
return false;
}
new rank = GetPlayerOrgRank(playerid) - 1;
format(dest, len, "%s", g_PlayerOrgRanks[playerid][rank]);
return true;
}
Compiler output:
warning 214: possibly a "const" array argument was intended: "dest"
Expected behavior
No warning should be emitted. dest[] is a write-only output buffer explicitly passed to format() which modifies it. The compiler should recognize that passing an array as a non-const argument to format() (a native function) marks it as modified/mutable, and therefore const is not appropriate.
Actual behavior
The compiler emits warning 214 suggesting dest should be const, which is incorrect — declaring it const would prevent format() from writing into it and break the intended functionality.
Root cause analysis
This appears to be related to the issue described in PR #302 (pawn-lang/compiler): the compiler's flow analysis fails to mark an array symbol as modified when it is passed as a non-const argument to a native function such as format().
In this case:
dest[] is passed directly to format() as the output destination.
format() is a native whose signature accepts a non-const array — meaning it mutates the buffer.
- The compiler does not propagate the "modified" flag from the native call back to the
dest symbol in the caller's scope.
- As a result, the compiler incorrectly concludes that
dest is never modified and suggests it be marked const.
Workaround
Adding a dummy write before the format() call suppresses the warning:
dest[0] = EOS; // forces compiler to recognize dest as mutable
format(dest, len, "...");
This should not be necessary and is purely a workaround for this false positive.
Bug Report: False positive
warning 214on mutable output buffer parameterDescription
The compiler emits
warning 214: possibly a "const" array argument was intendedon a function parameter that is intentionally mutable — it is used as an output buffer written to byformat(). The warning is a false positive because the parameter is never intended to be read-only.Compiler version
pawncc— compiler (version 3.10.10)Minimal reproducible example
Compiler output:
Expected behavior
No warning should be emitted.
dest[]is a write-only output buffer explicitly passed toformat()which modifies it. The compiler should recognize that passing an array as a non-constargument toformat()(a native function) marks it as modified/mutable, and thereforeconstis not appropriate.Actual behavior
The compiler emits
warning 214suggestingdestshould beconst, which is incorrect — declaring itconstwould preventformat()from writing into it and break the intended functionality.Root cause analysis
This appears to be related to the issue described in PR #302 (
pawn-lang/compiler): the compiler's flow analysis fails to mark an array symbol as modified when it is passed as a non-constargument to a native function such asformat().In this case:
dest[]is passed directly toformat()as the output destination.format()is a native whose signature accepts a non-constarray — meaning it mutates the buffer.destsymbol in the caller's scope.destis never modified and suggests it be markedconst.Workaround
Adding a dummy write before the
format()call suppresses the warning:This should not be necessary and is purely a workaround for this false positive.