GNU bug report logs - #23222
test: incorrect operator-precedence

Previous Next

Package: coreutils;

Reported by: Mattias Andrée <maandree <at> member.fsf.org>

Date: Tue, 5 Apr 2016 14:56:01 UTC

Severity: normal

Tags: confirmed, fixed

Done: Assaf Gordon <assafgordon <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Eric Blake <eblake <at> redhat.com>
To: Mattias Andrée <maandree <at> kth.se>
Cc: 23222 <at> debbugs.gnu.org, Mattias Andrée <maandree <at> member.fsf.org>
Subject: bug#23222: test: incorrect operator-precedence
Date: Tue, 5 Apr 2016 13:15:39 -0600
[Message part 1 (text/plain, inline)]
On 04/05/2016 12:36 PM, Mattias Andrée wrote:

>> Sorry, but here, you're wrong.  POSIX states:
>>
>> "4 arguments:
>>         If $1 is '!', negate the three-argument test of
>> $2, $3, and $4."
>>
>> which means this parses as:
>>
>> test ! \( '' -a '' \)
>>

> 
> XSI-conformant systems shall use the following precedence
> rules (highest to lowest), as documented (not quite as clearly)
> in the POSIX specifications:
> 

Only for more than four arguments:


>4 arguments:
    The results are unspecified.

    [OB XSI] [Option Start] On XSI-conformant systems, combinations of
primaries and operators shall be evaluated using the precedence and
associativity rules described previously. In addition, the string
comparison binary primaries '=' and "!=" shall have a higher precedence
than any unary primary. [Option End]


> The POSIX specification does indeed that that
> the number of arguments shall determine the
> precedence for 1 to 4 arguments. And the given
> rules do conflict with XSI. But if we run
> 
> test \( \( ... \) \) instead of test it seems
> only reasonable to use the XSI rules.

Yeah, other than the fact that -o and -a are marked obsolescent by POSIX
because they are inherently ambiguous, and therefore "The results are
unspecified" is a better phrase to rely on than any particular precedence.


> I believe that POSIX rule for 4 arguments shall
> be disregarded. It is clearly only intended for
> other binary operators than logical operators.

Sorry, but that's not how POSIX is worded.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]

This bug report was last modified 6 years and 265 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.