gcc does not warn when assigning a "larger" variable to a smaller one. Example: #include <stdio.h> int main(int argc, char **argv) { unsigned long i32; unsigned short i16; i32 = 0xffffffff; i16 = i32; /* should warn here, I think */ printf("i32 = 0x%lx, i16 = 0x%x\n", i32, (unsigned int)i16); printf("sizeof(i32) = %d, sizeof(i16) = %d\n", sizeof(i32), sizeof(i16)); return(0); } Release: unknown
State-Changed-From-To: open->analyzed State-Changed-Why: Confirmed. I don't think this is easy to fix with GCC's current architecture.
From: Dara Hazeghi <dhazeghi@yahoo.com> To: gcc-gnats@gcc.gnu.org Cc: Subject: Re: c/2707: gcc does not warn on truncate Date: Thu, 8 May 2003 01:31:22 -0700 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit- trail&database=gcc&pr=2707 Confirmed with mainline 20030507 Dara
still happens on mainline (20030524).
*** Bug 17968 has been marked as a duplicate of this bug. ***
*** Bug 25493 has been marked as a duplicate of this bug. ***
By using the patches of the Wcoercion project [*] and compiling with -Wcoercion, gcc reports for the testcase mentioned in the description: pr2707.c: In function 'main': pr2707.c:8: warning: coercion to 'short unsigned int' from 'long unsigned int' may alter its value So I guess this bug can be closed as soon as Wcoercion is integrated into mainline. [*] http://gcc.gnu.org/wiki/Wcoercion
Subject: Bug 2707 Author: manu Date: Fri Nov 24 01:50:33 2006 New Revision: 119143 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=119143 Log: 2006-11-24 Manuel Lopez-Ibanez <manu@gcc.gnu.org> PR c/2707 PR c++/26167 * c-common.c (conversion_warning): New. (convert_and_check): Call conversion_warning unless there is an overflow warning. * doc/invoke.texi (-Wconversion): Update description. testsuite/ * gcc.dg/Wconversion-integer.c: New. Supersedes Wconversion-negative-constants.c * gcc.dg/Wconversion-real.c: New. * gcc.dg/Wconversion-real-integer.c: New. * gcc.dg/Wconversion-negative-constants.c: Deleted. * g++.dg/warn/Wconversion1.C: Modified. Added: trunk/gcc/testsuite/gcc.dg/Wconversion-integer.c trunk/gcc/testsuite/gcc.dg/Wconversion-real-integer.c trunk/gcc/testsuite/gcc.dg/Wconversion-real.c Removed: trunk/gcc/testsuite/gcc.dg/Wconversion-negative-constants.c Modified: trunk/gcc/ChangeLog trunk/gcc/c-common.c trunk/gcc/doc/invoke.texi trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/g++.dg/warn/Wconversion1.C
Fixed in mainline.
*** Bug 260998 has been marked as a duplicate of this bug. *** Seen from the domain http://volichat.com Page where seen: http://volichat.com/adult-chat-rooms Marked for reference. Resolved as fixed @bugzilla.