This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/41388] New: -Wlogical-op produces a surprising message


With the following C fragment, compiled with the option -Wlogical-op,
one obtains:

main.c:1006: warning: logical '&&' with non-zero constant will always evaluate
as true

This message is surprising because a non-zero constant does not
prevent any global '&&' expression to return either true or false,
depending on the other operands.

Instead, i could have expected the following messages:

main.c: In function 'main':
main.c:1000: warning: logical '&&' with zero constant will always evaluate as
false
main.c:1009: warning: logical '||' with non-zero constant will always evaluate
as true

This behavior is consistent through at least GCC 4.3.2 and GCC 4.4.1, and also
through Cygwin-1.7, Solaris2.8 and Solaris2.10 (checked 4 configurations).
Also in C++.

Fragment is:
-------------------------------------------------------------------
#include <stdio.h>

//
int main(/*unsigned*/ int const argc, char const *const *const argv) {
//
# line 1000
  if (0 && (argc != 1) && (argc != 2) && 0) {
    fprintf(stderr, "argc=%u\n", argc);
  };
  if (0 || (argc == 1) || (argc == 2) || 0) {
    fprintf(stderr, "argc=%u\n", argc);
  };
  if (1 && (argc != 1) && (argc != 2) && 1) {
    fprintf(stderr, "argc=%u\n", argc);
  };
  if (1 || (argc == 1) || (argc == 2) || 1) {
    fprintf(stderr, "argc=%u\n", argc);
  };
  return(0);
}
-----------------------------------------------------


-- 
           Summary: -Wlogical-op produces a surprising message
           Product: gcc
           Version: 4.4.1
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: Denis dot Excoffier at airbus dot com
 GCC build triplet: sparc-sun-solaris2.8
  GCC host triplet: sparc-sun-solaris2.8
GCC target triplet: sparc-sun-solaris2.8


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41388


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]