Package: gcc
Version: 4.8.2-1

The following are all false positive warnings produced by -Wconversion.
 It should be smart enough to see that there is no problem.  It usually
it, but not in these cases.

gcc-4.8 -Wall -Wextra -Wconversion false.c
false.c: In function ‘main’:
false.c:18:26: warning: conversion to ‘unsigned char’ from ‘unsigned
int’ may alter its value [-Wconversion]
     unsigned char b6 = u >> 24;          /* warning (false positive) */
                          ^
false.c:19:26: warning: conversion to ‘unsigned char’ from ‘unsigned
int’ may alter its value [-Wconversion]
     unsigned char b7 = u >> 24u;         /* warning (false positive) */
                          ^
false.c:20:26: warning: conversion to ‘unsigned char’ from ‘unsigned
int’ may alter its value [-Wconversion]
     unsigned char b8 = u >> 31;          /* warning (false positive) */
                          ^
false.c:21:34: warning: conversion to ‘unsigned char’ from ‘unsigned
int’ may alter its value [-Wconversion]
     unsigned char b9 = (u >> 24) & 0xff; /* warning (false positive) */
                                  ^

C code to trigger the problem:

false.c:
// -*- Mode: C -*-
//
// Trigger false positive warnings with -Wconversion.
//
// gcc-4.8 -Wall -Wextra -Wconversion false.c

int main(int argc, char **argv)
{
    (void)argv;
    unsigned int u = (unsigned)argc;

    unsigned int u2 = u >> 24;
    unsigned char b1 = u2 & 0xff;        /* no warning */
    unsigned char b2 = u & 0xff;         /* no warning */
    unsigned char b3 = (u >> 23) & 0xff; /* no warning */
    unsigned char b4 = (u >> 24) & 0x7f; /* no warning */
    unsigned char b5 = (u >> 24) & 0xfe; /* no warning */
    unsigned char b6 = u >> 24;          /* warning (false positive) */
    unsigned char b7 = u >> 24u;         /* warning (false positive) */
    unsigned char b8 = u >> 31;          /* warning (false positive) */
    unsigned char b9 = (u >> 24) & 0xff; /* warning (false positive) */
// false.c: In function ‘main’:
// false.c:47:33: warning: conversion to ‘unsigned char’ from
// ‘unsigned int’ may alter its value [-Wconversion]
//     unsigned char b9 = (u >> 24) & 0xff; /* warning */
//                                 ^

    return b1+b2+b3+b4+b5+b6+b7+b8+b9;
}
// The same happens for other types, e.g. shifting 'unsigned long long'
// by at least 32 bits, assigning to 'unsigned', or shifting 'unsigned'
// by 16 bits, assigning to 'unsigned short'.

// GCC Version:
// Using built-in specs.
// COLLECT_GCC=gcc-4.8
// COLLECT_LTO_WRAPPER=/usr/lib/gcc/i486-linux-gnu/4.8/lto-wrapper
// Target: i486-linux-gnu
// Configured with: ../src/configure -v --with-pkgversion='Debian
// 4.8.2-1' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs
// --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++
// --prefix=/usr --program-suffix=-4.8 --enable-shared
// --enable-linker-build-id --libexecdir=/usr/lib
// --without-included-gettext --enable-threads=posix
// --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib
// --enable-nls --with-sysroot=/ --enable-clocale=gnu
// --enable-libstdcxx-debug --enable-libstdcxx-time=yes
// --enable-gnu-unique-object --enable-plugin --with-system-zlib
// --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo
// --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-i386/jre
// --enable-java-home
// --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-i386
// --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-i386
// --with-arch-directory=i386
// --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc
// --enable-targets=all --enable-multiarch --with-arch-32=i586
// --with-multilib-list=m32,m64,mx32 --with-tune=generic
// --enable-checking=release --build=i486-linux-gnu
// --host=i486-linux-gnu --target=i486-linux-gnu
// Thread model: posix
// gcc version 4.8.2 (Debian 4.8.2-1)


-- 
To UNSUBSCRIBE, email to debian-gcc-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/52854f7d.60...@ndwun.de

Reply via email to