* doc/m4.texi (Eval): Mention that the shift amount of << and >> is implicity truncated. Mention that radix > 10 can cause macro expansion. Enhance unit tests to cover this. --- doc/m4.texi | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/doc/m4.texi b/doc/m4.texi index 81476bc8..5a7980e7 100644 --- a/doc/m4.texi +++ b/doc/m4.texi @@ -7152,7 +7152,9 @@ Eval aware that parentheses may be required to enforce C precedence rules. Likewise, division by zero, even in the unused branch of a short-circuiting operator, is not always well-defined in other -implementations. +implementations. While GNU M4 implicitly masks the right argument +of a shift operator to 5 bits, other implementations may have undefined +behavior for a negative argument or a positive argument greater than 31. Following are some examples where the current version of M4 follows C precedence rules, but where older versions and some other @@ -7190,6 +7192,10 @@ Eval eval(`2 && (1 % 0)') @error{}m4:stdin:13: warning: eval: modulo by zero: '2 && (1 % 0)' @result{} +`0x'eval(`0x12345678>>40', `16') +@result{}0x123456 +`0x'eval(`0x12345678>>-8', `16') +@result{}0x12 @end example @cindex GNU extensions @@ -7246,7 +7252,10 @@ Eval for all other radices, the digits are @samp{0}, @samp{1}, @samp{2}, @dots{}. Beyond @samp{9}, the digits are @samp{a}, @samp{b} @dots{} up to @samp{z}. Lower and upper case letters can be used interchangeably -in numbers prefixes and as number digits. +in numbers prefixes and as number digits. Note that when using a radix +larger than 10, input literals may need to be quoted to avoid inadvertent +macro expansion, and the output of @code{eval} can also trigger macro +expansion unless coupled with @code{qindir}. Parentheses may be used to group subexpressions whenever needed. For the relational operators, a true relation returns @code{1}, and a false @@ -7275,13 +7284,17 @@ Eval @result{}676 define(`foo', `666') @result{} +eval(`0r36:fOo', `36') +@result{}666 +qindir(`eval', `0r36:fOo', `36') +@result{}foo eval(`foo / 6') -@error{}m4:stdin:11: warning: eval: bad input: 'foo / 6' +@error{}m4:stdin:13: warning: eval: bad input: 'foo / 6' @result{} eval(foo / 6) @result{}111 eval(`1+') -@error{}m4:stdin:13: warning: eval: missing operand: '1+' +@error{}m4:stdin:15: warning: eval: missing operand: '1+' @result{} @end example -- 2.49.0 _______________________________________________ M4-patches mailing list M4-patches@gnu.org https://lists.gnu.org/mailman/listinfo/m4-patches