As documented, %MACRO expects a particular format
for its parameter count. While the first count can
be followed by '-', '+', or nothing, that restric-
tion is not enforced. For example, a '=' (e.g. a
mis-typed '-'), or a '*' (i.e. missing '-') should
cause a warning or an error.
%macro mmac1 1=
nop
%endmacro
mmac1 x
%macro mmac2 1*
nop
%endmacro
mmac2 x
The same probably applies to %IFMACRO -- I haven't
checked it yet, since it was introduced only very
recently. (Oh, and while we are at that -- shouldn't
it have been named %IFDEFM, to match %IFDEF? :-)
Logged In: YES
user_id=2127992
Originator: NO
This item has been resolved; the fix has been checked into git (http://repo.or.cz/w/nasm.git) and will be in the next release.
You can usually also obtain a nightly snapshot at ftp://ftp.zytor.com/pub/nasm/snapshots/; the snapshot robot usually runs some time between 09:00 and 10:30 UTC.
Logged In: YES
user_id=804543
Originator: NO
Victor's checkin added an unconditional
warning for cases where the multi-line
macro definition has "too many" default
parameters.
This warning should be suppressible.
And it should not apply to the variadic
forms (that have the trailing "+").
Here is the necessary fix:
# diff preproc.c.old preproc.c
1883,1884c1883,1884
< if(def->defaults && def->ndefs > def->nparam_max - def->nparam_min)
< error(ERR_WARNING, "too much default macro parameters");
---
> if(def->defaults && def->ndefs > def->nparam_max - def->nparam_min && !def->plus)
> error(ERR_WARNING | ERR_WARN_MNP, "too many default macro parameters");
# cat z.asm
%MACRO mmac_fix 1 a
; While defined to take one parameter, any invocation will
; see two, due to the default parameter.
%warning %0 %1 %2 %3 %4 %5
%ENDMACRO
mmac_fix one
%MACRO mmac_var 1-2 a,b
; While defined to take one or two parameters, invocations
; will see three, due to the default parameters.
%warning %0 %1 %2 %3 %4 %5
%ENDMACRO
mmac_var one
mmac_var one,two
%MACRO mmac_plus 1-2+ a,b
; This does not warn. Although this looks like two default
; parameters, it ends up being only one: the "+" limits it
; to two parameters; if invoked without a second parameter
; the second parameter will be "a,b".
%warning %0 %1 %2 %3 %4 %5
%ENDMACRO
mmac_plus one
mmac_plus one,two
mmac_plus one,two,three
%MACRO mmac_star 1-* a,b
; This does not warn. Because the "*" extends the range of
; parameters to infinity, the "a,b" default parameters can
; not exceed that range.
%warning %0 %1 %2 %3 %4 %5
%ENDMACRO
mmac_star one
mmac_star one,two
mmac_star one,two,three
# ./nasm z.asm -w+macro-params
z.asm:1: warning: too many default macro parameters
z.asm:6: (mmac_fix:3) %warning: 2 one a
z.asm:8: warning: too many default macro parameters
z.asm:13: (mmac_var:3) %warning: 3 one a b
z.asm:14: (mmac_var:3) %warning: 3 one two b
z.asm:23: (mmac_plus:5) %warning: 2 one a,b
z.asm:24: (mmac_plus:5) %warning: 2 one two
z.asm:25: (mmac_plus:5) %warning: 2 one two,three
z.asm:33: (mmac_star:4) %warning: 3 one a b
z.asm:34: (mmac_star:4) %warning: 3 one two b
z.asm:35: (mmac_star:4) %warning: 3 one two three
# ./nasm z.asm -w-macro-params
z.asm:6: (mmac_fix:3) %warning: 2 one a
z.asm:13: (mmac_var:3) %warning: 3 one a b
z.asm:14: (mmac_var:3) %warning: 3 one two b
z.asm:23: (mmac_plus:5) %warning: 2 one a,b
z.asm:24: (mmac_plus:5) %warning: 2 one two
z.asm:25: (mmac_plus:5) %warning: 2 one two,three
z.asm:33: (mmac_star:4) %warning: 3 one a b
z.asm:34: (mmac_star:4) %warning: 3 one two b
z.asm:35: (mmac_star:4) %warning: 3 one two three
Logged In: YES
user_id=58697
Originator: NO
When submitting diffs, please use "diff -u". Thanks.
Logged In: YES
user_id=2127992
Originator: NO
I've added the macro-defaults warning class because macro-params is about something else.
See commit 22343c2.