https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69602

            Bug ID: 69602
           Summary: over-ambitious logical-op warning on EAGAIN vs
                    EWOULDBLOCK
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eblake at redhat dot com
  Target Milestone: ---

POSIX says that EAGAIN and EWOULDBLOCK may be identical, but also that they may
be distinct.  Therefore, well-written portable code MUST check for both values
in some circumstances.

However, as shown by the sample code below, gcc 6.0's new warning is
over-ambitious, and is likely to _cause_ rather than cure user bugs, when
uninformed users unaware that Linux has the two errno values equal dumb down
the code to silence the warning, but in the process break their code on other
platforms where it is important to check for both values.

$ cat foo.c
#include <errno.h>
int main(void) {
  if (errno == EAGAIN || errno == EWOULDBLOCK)
    return 1;
  return 0;
}
$ gcc -o foo foo.c -Werror=logical-op
foo.c: In function 'main':
foo.c:3:23: error: logical 'or' of equal expressions [-Werror=logical-op]
   if (errno == EAGAIN || errno == EWOULDBLOCK)
                       ^~
cc1: some warnings being treated as errors
$ gcc --version | head -n1
gcc (GCC) 6.0.0 20160129 (Red Hat 6.0.0-0.7)

Reply via email to