https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70378
Bug ID: 70378 Summary: [5.3] inconsistant warnings with -Wconversion for different types Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: daniel.f.starke at freenet dot de Target Milestone: --- Tested with GCC 4.4.3 and 5.3.0 whereas 5.3.0 was configured as Configured with: ../../src/gcc-5.3.0/configure --host=x86_64-w64-mingw32 --enable-languages=c,c++ --enable-seh-exceptions --enable-threads=posix --disable-nls --disable-shared --enable-static --enable-fully-dynamic-string --enable-lto --enable-plugins --enable-libgomp --with-dwarf2 --disable-win32-registry --enable-version-specific-runtime-libs --prefix=/mingw64-64 --with-sysroot=/mingw64-64 --target=x86_64-w64-mingw32 --enable-targets=all --enable-checking=release --with-gmp=/usr/new-gcc/lib/gmp-5.0.5 --with-mpfr=/usr/new-gcc/lib/mpfr-2.4.2 --with-mpc=/usr/new-gcc/lib/mpc-0.9 --with-isl=/usr/new-gcc/lib/isl-0.12.2 --with-cloog=/usr/new-gcc/lib/cloog-0.18.3 --with-host-libstdcxx='-lstdc++ -lsupc++' --disable-cloog-version-check --enable-cloog-backend=isl #include <stdio.h> #include <stdlib.h> #include <stdint.h> #define PARSE(Type) \ do { \ const char * a = str; \ Type b = 0; \ while (*a != 0) { \ b = (Type)((b * 10) + (Type)(*a) - '0'); \ a++; \ } \ printf(#Type " = %u\n", (unsigned int)b); \ } while (0) int main() { const char * str = "123"; PARSE(int8_t); PARSE(int16_t); PARSE(int32_t); PARSE(int64_t); PARSE(uint8_t); PARSE(uint16_t); PARSE(uint32_t); PARSE(uint64_t); PARSE(unsigned int); PARSE(unsigned); return EXIT_SUCCESS; } This code only produces a warning for uint32_t when compiled with -Wconversion: test.c:10:24: warning: conversion to 'uint32_t {aka unsigned int}' from 'char' may change the sign of the result [-Wsign-conversion] b = (Type)((b * 10) + (Type)(*a) - '0'); \ ^ test.c:25:2: note: in expansion of macro 'PARSE' PARSE(uint32_t); uint32_t was defined as: typedef unsigned uint32_t;