public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/33514] New: Inconsistent warning for compile-time integer overflow
@ 2007-09-21 5:27 mec at google dot com
2007-09-21 5:28 ` [Bug c++/33514] " mec at google dot com
2008-12-31 18:10 ` [Bug c++/33514] Inconsistent warning for compile-time integer overflow in struct compared to toplevel pinskia at gcc dot gnu dot org
0 siblings, 2 replies; 3+ messages in thread
From: mec at google dot com @ 2007-09-21 5:27 UTC (permalink / raw)
To: gcc-bugs
This is with gcc 4.3-20070914 snapshot.
The attached program has four sites with compile-time integer overflow: the
initializations of h4, h8, bp_i:h, and bp_lli:h. Only the last of these draws
a warning.
mec@hollerith:~/exp-integer-overflow$ cat z5.cc
#include <stdio.h>
int l4 = 0x01010101;
int h4 = l4 * 0x80;
long long int l8 = 0x0101010101010101ll;
long long int h8 = l8 * 0x80;
template <class T> struct BitPattern {
// For int32:
// half_ones = 0x00001111
// l = 0x01010101
// h = 0x80808080
static const T half_ones = (static_cast<T>(1) << (sizeof(T)*4)) - 1;
static const T l = (sizeof(T) == 1) ? 1 : (half_ones / 0xff * (half_ones +
2));
static const T h = l * 0x80;
};
BitPattern<int> bp_i;
BitPattern<long long int> bp_lli;
int main() {
printf("%16.16llx\n", bp_lli.half_ones);
printf("%16.16llx\n", bp_lli.l);
printf("%16.16llx\n", bp_lli.h);
return 0;
}
mec@hollerith:~/exp-integer-overflow$
/home/mec/gcc-4.3-20070914/install/bin/g++ -Wall -S z5.cc
z5.cc: In instantiation of 'const long long int BitPattern<long long int>::h':
z5.cc:25: instantiated from here
z5.cc:16: warning: integer overflow in expression
--
Summary: Inconsistent warning for compile-time integer overflow
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: mec at google dot com
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33514
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/33514] Inconsistent warning for compile-time integer overflow
2007-09-21 5:27 [Bug c++/33514] New: Inconsistent warning for compile-time integer overflow mec at google dot com
@ 2007-09-21 5:28 ` mec at google dot com
2008-12-31 18:10 ` [Bug c++/33514] Inconsistent warning for compile-time integer overflow in struct compared to toplevel pinskia at gcc dot gnu dot org
1 sibling, 0 replies; 3+ messages in thread
From: mec at google dot com @ 2007-09-21 5:28 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from mec at google dot com 2007-09-21 05:28 -------
Created an attachment (id=14235)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=14235&action=view)
Test program
Compile with: gcc -Wall -S z5.cc
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33514
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/33514] Inconsistent warning for compile-time integer overflow in struct compared to toplevel
2007-09-21 5:27 [Bug c++/33514] New: Inconsistent warning for compile-time integer overflow mec at google dot com
2007-09-21 5:28 ` [Bug c++/33514] " mec at google dot com
@ 2008-12-31 18:10 ` pinskia at gcc dot gnu dot org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-12-31 18:10 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from pinskia at gcc dot gnu dot org 2008-12-31 18:07 -------
This happens also with non templates:
s/template <class T> struct BitPattern {/typedef long long T; struct BitPattern
{/
:).
Note 4.1.1 did not warn in either place. I don't know if we should be warning
in both or none so I am not going to mark this as a regression.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
GCC build triplet|i686-pc-linux-gnu |
GCC host triplet|i686-pc-linux-gnu |
GCC target triplet|i686-pc-linux-gnu |
Keywords| |diagnostic
Last reconfirmed|0000-00-00 00:00:00 |2008-12-31 18:07:33
date| |
Summary|Inconsistent warning for |Inconsistent warning for
|compile-time integer |compile-time integer
|overflow |overflow in struct compared
| |to toplevel
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33514
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-12-31 18:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-21 5:27 [Bug c++/33514] New: Inconsistent warning for compile-time integer overflow mec at google dot com
2007-09-21 5:28 ` [Bug c++/33514] " mec at google dot com
2008-12-31 18:10 ` [Bug c++/33514] Inconsistent warning for compile-time integer overflow in struct compared to toplevel pinskia at gcc dot gnu dot org
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).