I believe this needs to be relooked at. It is still an issue, and the bug seems to come from the gcc/g++ compilers themselves.
To wit (quoting myself from a board where I was discussing this issue): ~~~Start Self Quote~~~ Outline of the problem: C++ Software written by someone else for server-to-server communication with MUD softwares, uses htons() g++ is spitting out the following error: error: conversion to short unsigned int from int may alter its value That line of code: sa.sin_port = htons( siteinfo->port ); Other relevant code: struct sockaddr_in sa; unsigned short int port; /* Port the server listens on */ Using --save-temps compiiler flag and grepping the resulting .ii file for htons: extern uint16_t htons (uint16_t __hostshort) Checking typedef for unit16_t also using grep on the .ii file: typedef unsigned short int __uint16_t; All proper header files for htons() & network sockets (<sys/socket.h>, <arpa/inet.h> and <netinet/in.h>) included. So, am I missing something here... or is this a bad warning from the compiler? g++ flags in use: [code]W_FLAGS = -Wall -Werror -Wformat-security -Wshadow -Wpointer-arith -Wcast-align -Wredundant-decls -Wconversion -pedantic CFLAGS = -g2 -Os $(W_FLAGS) LFLAGS = -g2 -lz[/code] make/g++/ln version infos: $ make --version GNU Make 3.81 Copyright (C) 2006 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. $ g++ --version g++ (GCC) 4.4.1 Copyright (C) 2009 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. $ ln --version ln (GNU coreutils) 7.5 Copyright (C) 2009 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Written by Mike Parker and David MacKenzie. ~~~End Self Quote~~~ Now, as the original reporter of this bug mentioned, it ONLY happens with higher levels of optimization. Take it or leave it, but this is NOT "invalid". g++ -v compilation command output: $ g++ -v -g2 -Os -Wall -Werror -Wformat-security -Wshadow -Wpointer-arith -Wcast-align -Wredundant-decls -Wconversion -pedantic --save-temps -c -o imc.o imc.c Using built-in specs. Target: i586-manbo-linux-gnu Configured with: ../configure --prefix=/usr --libexecdir=/usr/lib --with-slibdir=/lib --with-bugurl=https://qa.mandriva.com/ --mandir=/usr/share/man --infodir=/usr/share/info --enable-checking=release --enable-languages=c,c++,ada,fortran,objc,obj-c++,java --build=i586-manbo-linux-gnu --host=i586-manbo-linux-gnu --with-cpu=generic --with-system-zlib --enable-threads=posix --enable-shared --enable-objc-gc --enable-long-long --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --enable-java-awt=gtk --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-gtk-cairo --disable-libjava-multilib --enable-ssp --disable-libssp --disable-werror --with-ppl --with-cloog --with-python-dir=/lib/python2.6/site-packages Thread model: posix gcc version 4.4.1 (GCC) COLLECT_GCC_OPTIONS='-v' '-g2' '-Os' '-Wall' '-Werror' '-Wformat-security' '-Wshadow' '-Wpointer-arith' '-Wcast-align' '-Wredundant-decls' '-Wconversion' '-pedantic' '-save-temps' '-c' '-o' 'imc.o' '-shared-libgcc' '-mtune=generic' /usr/lib/gcc/i586-manbo-linux-gnu/4.4.1/cc1plus -E -quiet -v -D_GNU_SOURCE imc.c -mtune=generic -Wall -Werror -Wformat-security -Wshadow -Wpointer-arith -Wcast-align -Wredundant-decls -Wconversion -pedantic -g2 -fworking-directory -Os -fpch-preprocess -o imc.ii ignoring nonexistent directory "/usr/lib/gcc/i586-manbo-linux-gnu/4.4.1/include-fixed" ignoring nonexistent directory "/usr/lib/gcc/i586-manbo-linux-gnu/4.4.1/../../../../i586-manbo-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /usr/lib/gcc/i586-manbo-linux-gnu/4.4.1/../../../../include/c++/4.4.1 /usr/lib/gcc/i586-manbo-linux-gnu/4.4.1/../../../../include/c++/4.4.1/i586-manbo-linux-gnu /usr/lib/gcc/i586-manbo-linux-gnu/4.4.1/../../../../include/c++/4.4.1/backward /usr/local/include /usr/lib/gcc/i586-manbo-linux-gnu/4.4.1/include /usr/include End of search list. COLLECT_GCC_OPTIONS='-v' '-g2' '-Os' '-Wall' '-Werror' '-Wformat-security' '-Wshadow' '-Wpointer-arith' '-Wcast-align' '-Wredundant-decls' '-Wconversion' '-pedantic' '-save-temps' '-c' '-o' 'imc.o' '-shared-libgcc' '-mtune=generic' /usr/lib/gcc/i586-manbo-linux-gnu/4.4.1/cc1plus -fpreprocessed imc.ii -quiet -dumpbase imc.c -mtune=generic -auxbase-strip imc.o -g2 -Os -Wall -Werror -Wformat-security -Wshadow -Wpointer-arith -Wcast-align -Wredundant-decls -Wconversion -pedantic -version -o imc.s GNU C++ (GCC) version 4.4.1 (i586-manbo-linux-gnu) compiled by GNU C version 4.4.1, GMP version 4.3.1, MPFR version 2.4.1. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: d87da6367e390a0648b100f32b6ee212 cc1plus: warnings being treated as errors imc.c: In function bool imc_startup_port(): imc.c:5895: error: conversion to short unsigned int from int may alter its value -- Summary: Broken htons, invalid conversion warning Product: gcc Version: 4.4.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: ralgith at gmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44924