Bug 2707 - gcc does not warn on truncate
Summary: gcc does not warn on truncate
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: unknown
: P3 enhancement
Target Milestone: 4.3.0
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
: 17968 25493 (view as bug list)
Depends on:
Blocks:
 
Reported: 2001-05-01 11:06 UTC by jhabermann
Modified: 2014-02-16 13:16 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 2.97 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1 3.1.1 3.1.2 3.2 3.2.1 3.2.2 3.2.3 3.3 3.3.1 3.3.2 3.3.3 3.4.0 4.0.0
Last reconfirmed: 2005-12-10 05:26:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jhabermann 2001-05-01 11:06:00 UTC
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
Comment 1 Neil Booth 2001-10-30 15:10:51 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Confirmed.  I don't think this is easy to fix with GCC's
    current architecture.
Comment 2 Dara Hazeghi 2003-05-08 01:31:22 UTC
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
Comment 3 Andrew Pinski 2003-05-24 23:54:48 UTC
still happens on mainline (20030524).
Comment 4 Andrew Pinski 2004-10-13 11:44:22 UTC
*** Bug 17968 has been marked as a duplicate of this bug. ***
Comment 5 Andrew Pinski 2005-12-19 17:33:18 UTC
*** Bug 25493 has been marked as a duplicate of this bug. ***
Comment 6 Manuel López-Ibáñez 2006-09-16 00:31:21 UTC
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
Comment 7 Manuel López-Ibáñez 2006-11-24 01:50:46 UTC
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

Comment 8 Manuel López-Ibáñez 2006-11-24 01:59:12 UTC
Fixed in mainline.
Comment 9 Jackie Rosen 2014-02-16 13:16:09 UTC Comment hidden (spam)