<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">On 14-02-10 06:57 PM, Keith Packard
      wrote:<br>
    </div>
    <blockquote cite="mid:86a9dyo71k.fsf@miki.keithp.com" type="cite">
      <pre wrap="">Gaetan Nadon <a class="moz-txt-link-rfc2396E" href="mailto:memsize@videotron.ca"><memsize@videotron.ca></a> writes:

Ok, except for -Wshadow, these are all legitimate warnings (and a few
actual bugs!) that we should fix. I would love for someone to explain
why my build doesn't generate the useful warnings and why Gaedon's
compiler is generating the -Wshadow ones...

Thanks, Gaedon!

</pre>
      <blockquote type="cite">
        <pre wrap="">     I have a total of 238 warnings.
      199 -Wshadow
</pre>
      </blockquote>
      <pre wrap="">
All of these are badly named libc/libm functions:

        y0
        y1
        gamma
        index
        remainder
        
I am not seeing any -Wshadow warnings between functions and local
variables. This example:

        double z1;

        double y1(double x) { return 0; }

        void foo (void) {
                int z1 = 0;
                int y1 = 0;
        }

Generates a single warning for me:

        $ cc -Wshadow -c foo.c

        foo.c: In function ‘foo’:
        foo.c:6:6: warning: declaration of ‘z1’ shadows a global declaration [-Wshadow]
          int z1 = 0;
              ^
        foo.c:1:8: warning: shadowed declaration is here [-Wshadow]
         double z1;
                ^</pre>
    </blockquote>
    <blockquote><tt>nadon@memsize:~/xorg/src$ cc -Wshadow -c foo.c</tt><tt><br>
      </tt><tt>foo.c: In function ‘foo’:</tt><tt><br>
      </tt><tt>foo.c:6:6: warning: declaration of ‘z1’ shadows a global
        declaration [-Wshadow]</tt><tt><br>
      </tt><tt>foo.c:1:8: warning: shadowed declaration is here
        [-Wshadow]</tt><tt><br>
      </tt><tt>foo.c:7:6: warning: declaration of ‘y1’ shadows a global
        declaration [-Wshadow]</tt><tt><br>
      </tt><tt>foo.c:3:8: warning: shadowed declaration is here
        [-Wshadow]</tt><tt><br>
      </tt></blockquote>
    <blockquote cite="mid:86a9dyo71k.fsf@miki.keithp.com" type="cite">
      <pre wrap="">

What version of gcc are you using? And, what compiler flags do you end
up with?

        $ gcc --version
        gcc (Debian 4.8.2-14) 4.8.2

        $ make V=1
        gcc -std=gnu99 -DHAVE_CONFIG_H -I. -I../include -DHAVE_DIX_CONFIG_H -Wall -Wpointer-arith -Wmissing-declarations -Wformat=2 -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Wbad-function-cast -Wold-style-definition -Wdeclaration-after-statement -Wunused -Wuninitialized -Wshadow -Wmissing-noreturn -Wmissing-format-attribute -Wredundant-decls -Wlogical-op -Werror=implicit -Werror=nonnull -Werror=init-self -Werror=main -Werror=missing-braces -Werror=sequence-point -Werror=return-type -Werror=trigraphs -Werror=array-bounds -Werror=write-strings -Werror=address -Werror=int-to-pointer-cast -Werror=pointer-to-int-cast -fno-strict-aliasing -fno-strict-aliasing -D_BSD_SOURCE -DHAS_FCHOWN -DHAS_STICKY_DIR_BIT -I/local/xorg/include -I/local/xorg/include/pixman-1 -I/local/xorg/include/X11/dri -I/local/xorg/include/libdrm -I/usr/include/freetype2 -I../include -I../include -I../Xext -I../composite -I../damageext -I../xfixes -I../Xi -I../mi -I../miext/sync -I../miext/shadow -I../m
ext/damage -I../render -I../randr -I../fb -I../dbe -I../present -fvisibility=hidden -O2 -g -MT mitrap.lo -MD -MP -MF .deps/mitrap.Tpo -c mitrap.c  -fPIC -DPIC -o .libs/mitrap.o
</pre>
    </blockquote>
    <blockquote><tt>nadon@memsize:~/xorg/src/xserver/render$ gcc
        --version</tt><tt><br>
      </tt><tt>gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3</tt><tt><br>
      </tt><tt>Copyright (C) 2011 Free Software Foundation, Inc.</tt><tt><br>
      </tt><tt>This is free software; see the source for copying
        conditions.  There is NO</tt><tt><br>
      </tt><tt>warranty; not even for MERCHANTABILITY or FITNESS FOR A
        PARTICULAR PURPOSE.</tt><tt><br>
      </tt><tt><br>
      </tt><tt>nadon@memsize:~/xorg/src/xserver/render$ rm -f mitrap.lo</tt><tt><br>
      </tt><tt>nadon@memsize:~/xorg/src/xserver/render$ make V=1</tt><tt><br>
      </tt><tt>/bin/bash ../libtool  --tag=CC   --mode=compile gcc
        -std=gnu99 -DHAVE_CONFIG_H -I. -I../include   
        -DHAVE_DIX_CONFIG_H -Wall -Wpointer-arith -Wmissing-declarations
        -Wformat=2 -Wstrict-prototypes -Wmissing-prototypes
        -Wnested-externs -Wbad-function-cast -Wold-style-definition
        -Wdeclaration-after-statement -Wunused -Wuninitialized -Wshadow
        -Wmissing-noreturn -Wmissing-format-attribute -Wredundant-decls
        -Wlogical-op -Werror=implicit -Werror=nonnull -Werror=init-self
        -Werror=main -Werror=missing-braces -Werror=sequence-point
        -Werror=return-type -Werror=trigraphs -Werror=array-bounds
        -Werror=write-strings -Werror=address
        -Werror=int-to-pointer-cast -Werror=pointer-to-int-cast
        -fno-strict-aliasing -fno-strict-aliasing -D_BSD_SOURCE
        -DHAS_FCHOWN -DHAS_STICKY_DIR_BIT
        -I/home/nadon/xorg/inst/include
        -I/home/nadon/xorg/inst/include/pixman-1
        -I/home/nadon/xorg/inst/include/X11/dri
        -I/home/nadon/xorg/inst/include/libdrm
        -I/usr/include/freetype2   -I../include -I../include -I../Xext
        -I../composite -I../damageext -I../xfixes -I../Xi -I../mi
        -I../miext/sync -I../miext/shadow  -I../miext/damage -I../render
        -I../randr -I../fb -I../dbe -I../present -fvisibility=hidden -g
        -O2 -MT mitrap.lo -MD -MP -MF .deps/mitrap.Tpo -c -o mitrap.lo
        mitrap.c</tt><br>
    </blockquote>
    I checked the list of warnings flags and include directives are the
    same as expected.<br>
    <br>
    <blockquote cite="mid:86a9dyo71k.fsf@miki.keithp.com" type="cite">
      <pre wrap="">
We need to get the compiler to stop emiting these warnings as it's just
not reasonable to require that local variables not have the name 'y1' or
'index'. I'm very resistant to asserting that these are bugs in the X
server code; how can we make your compiler work like mine? Is it just
that you need a newer version of gcc? Or is it that gcc running in
64-bit mode is different?

</pre>
      <blockquote type="cite">
        <pre wrap="">       35 -Wunused-result
</pre>
      </blockquote>
      <pre wrap="">
28 from test/signal-logging.c, 5 legit bugs in os, 2 bugs in
xkmread.c. Why am I not seeing these? I cannot get gcc to emit these warnings...

The signal-logging one is trivial to fix (just assert that fgets returns
non-NULL). The bugs in os and xkbread should also be fairly easy to fix,
if I could make gcc tell me about them.

</pre>
      <blockquote type="cite">
        <pre wrap="">        2 -Wpointer-arith
</pre>
      </blockquote>
      <pre wrap="">
64-bit compiler bug in the test code.

</pre>
      <blockquote type="cite">
        <pre wrap="">        1 -Wformat
</pre>
      </blockquote>
      <pre wrap="">
test/hashtabletest.c format bug

</pre>
      <blockquote type="cite">
        <pre wrap="">        1 -Wunused-function
</pre>
      </blockquote>
      <pre wrap="">
That's bswap_CARD64, the only warning I'm getting at present

</pre>
    </blockquote>
    Fascinating. <br>
    <br>
    <a class="moz-txt-link-freetext" href="http://gcc.gnu.org/gcc-4.8/changes.html">http://gcc.gnu.org/gcc-4.8/changes.html</a>:<br>
    <ul>
      <li>The option <code>-Wshadow</code> no longer warns if a
        declaration shadows a function declaration, unless the former
        declares a function or pointer to function, because this is <a
          href="https://lkml.org/lkml/2006/11/28/239">a common and valid
          case in real-world code</a>.</li>
    </ul>
    Hopefully people will report what they have on their platforms.
    Meanwhile, I'll see if I can setup vmware images and find which
    versions of gcc finds what. A short test case for each missing
    warning would be easy to test from a Live CD rather than setting up
    the whole build environment for X.<br>
    <br>
    <br>
    <br>
    <br>
    <br>
  </body>
</html>