Re: Sparse crash when mixing int and enum in ternary operator

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wednesday 24 of March 2010 11:07:04 Christopher Li wrote:
> That is just too much. Most of the warning is coming from enum or
> operation. e.g.
> .type = KW_SPECIFIER | KW_SHORT,
> lookup_keyword(token->ident, NS_KEYWORD | NS_TYPEDEF);

Looking once again, I don't think that's the case.  The warnings do not come 
from the "enum or" operation, but they come from passing the integral result 
to enum variable (or arg).  Instead of weaking my patch, we may improve the 
code of sparse and add explicit casts back to enum:

    .type = (enum keyword) (KW_SPECIFIER | KW_SHORT),
    lookup_keyword(token->ident, (enum namespace) (NS_KEYWORD | NS_TYPEDEF));


The whole problem can be narrowed down to a simple test-case:

    int main()
    {
        enum {
            A = 0x1,
            B = 0x2
        } val = A | B;

        return val;
    }


Here is what sparse gives:
$ ./sparse enum.c
enum.c:1:10: warning: non-ANSI function declaration of function 'main'
enum.c:6:15: warning: conversion of
enum.c:6:15:     int to
enum.c:6:15:     int enum <noident>


Here is what g++ gives:
$ g++ enum.c
enum.c: In function ‘int main()’:
enum.c:6: error: invalid conversion from ‘int’ to ‘main()::<anonymous enum>’

Kamil
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux