develooper Front page | perl.perl5.porters | Postings from March 2021

weird gcc utf8.c compiler warning

Thread Next
From:
Dave Mitchell
Date:
March 29, 2021 15:45
Subject:
weird gcc utf8.c compiler warning
Message ID:
YGH2KKtmpy937c1y@iabyn.com
While looking into a gcc compiler warning when building utf8.o,
I've reduced the offending code to the following standalone file.
I'm struggling to see why the warning makes any sense. I'm also slightly
confused that the compiler doesn't even need -Wall or -W[something] to
emit the warning. This is Linux (Fedora 33, X86_64).

Anyone have any thoughts?


$ gcc --version
gcc (GCC) 10.2.1 20201125 (Red Hat 10.2.1-9)
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ cat c.c
typedef long unsigned int UV;
typedef unsigned char U8;

int main(int argc, char**argv)
{
    UV min_uv =
        (
             ((U8)
                (
                    (
                     (void)2
                       ,
                       0x80
                    )
                    |
                    3
                )
            )
          &
            0xff
        );
}

$ gcc -c c.c
c.c: In function ‘main’:
c.c:7:9: warning: overflow in conversion from ‘int’ to ‘UV’ {aka ‘long unsigned int’} changes value from ‘131’ to ‘131’ [-Woverflow]
    7 |         (
      |         ^
$ 


-- 
Monto Blanco... scorchio!

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About