public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* No warning on type truncation
@ 2008-08-03 19:04 Ankur Arora
  2008-08-03 19:18 ` Brian Dessent
  0 siblings, 1 reply; 3+ messages in thread
From: Ankur Arora @ 2008-08-03 19:04 UTC (permalink / raw)
  To: gcc-help

Hi,

In the following program I am truncating a value from long to int (on
a 64 bit machine):
$ cat trunc.c
int  main() {
int t2;
long t1 = 0xfeed00000000;

        t2 = t1;

        return 0;
}

That, however doesn't result in any warnings even though -Wall and
-Wextra are enabled:
$ gcc -Wextra -Wall trunc.c
$ gcc -v
Using built-in specs.
Target: x86_64-pc-linux-gnu
Configured with:
/var/tmp/portage/sys-devel/gcc-4.1.2/work/gcc-4.1.2/configure
--prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.1.2
--includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.1.2
--mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.1.2/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.1.2/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4
--host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu
--disable-altivec --enable-nls --without-included-gettext
--with-system-zlib --disable-checking --disable-werror
--enable-secureplt --enable-multilib --enable-libmudflap
--disable-libssp --disable-libgcj
--enable-languages=c,c++,d,objc,obj-c++,treelang,fortran
--enable-shared --enable-threads=posix --enable-__cxa_atexit
--enable-clocale=gnu
Thread model: posix
gcc version 4.1.2 20070214 (  (gdc 0.24, using dmd 1.020)) (Gentoo 4.1.2 p1.1)

I cannot find any relevant option in the manual which enables
truncation warnings.
What am I missing?

Thanks,
Ankur

-- 
667:
 The neighbor of the beast.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: No warning on type truncation
  2008-08-03 19:04 No warning on type truncation Ankur Arora
@ 2008-08-03 19:18 ` Brian Dessent
  2008-08-03 19:49   ` Ankur Arora
  0 siblings, 1 reply; 3+ messages in thread
From: Brian Dessent @ 2008-08-03 19:18 UTC (permalink / raw)
  To: Ankur Arora; +Cc: gcc-help

Ankur Arora wrote:

> I cannot find any relevant option in the manual which enables
> truncation warnings.
> What am I missing?

-Wconversion with 4.4 does warn:

tc.c: In function 'main':
tc.c:5: warning: conversion to 'int' from 'long int' may alter its value

I think that this was added in 4.3, or rather the -Wconversion prior to
4.3 meant something different and less useful.

Brian

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: No warning on type truncation
  2008-08-03 19:18 ` Brian Dessent
@ 2008-08-03 19:49   ` Ankur Arora
  0 siblings, 0 replies; 3+ messages in thread
From: Ankur Arora @ 2008-08-03 19:49 UTC (permalink / raw)
  To: gcc-help

> -Wconversion with 4.4 does warn:
>
> tc.c: In function 'main':
> tc.c:5: warning: conversion to 'int' from 'long int' may alter its value
>
> I think that this was added in 4.3, or rather the -Wconversion prior to
> 4.3 meant something different and less useful.
Yes, I did try with -Wconversion in 4.1.2 but that worked only for conversions
across function calls/prototypes.


Thanks for the pointer,
Ankur

-- 
667:
 The neighbor of the beast.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-08-03 19:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-03 19:04 No warning on type truncation Ankur Arora
2008-08-03 19:18 ` Brian Dessent
2008-08-03 19:49   ` Ankur Arora

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).