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/56153] New: False warning about signed and unsigned type in conditional expression


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

             Bug #: 56153
           Summary: False warning about signed and unsigned type in
                    conditional expression
    Classification: Unclassified
           Product: gcc
           Version: 4.6.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: d.daniel@propharma.ch


The following code creates a warning "signed and unsigned type in conditional
expression" but there is no such comparison:

typedef struct {
   unsigned int num;
   const char *str;
} FooBar;

FooBar *foo = (FooBar *)malloc (sizeof (FooBar));
foo->num = 0; 
foo->str = "Hello World";
fprintf (stdout, "%d", foo != 0 ? foo->num : -1);

If instead, the following code gets compiled, no warning is issued:

// .. the same as above
fprintf (stdout, "%d", foo != 0 ? foo->num : 1);


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