public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/38855] New: evaluation of reinterpret_cast with -O2
@ 2009-01-15 13:36 ElGringo at gmx dot at
2009-01-15 14:38 ` [Bug c++/38855] " rguenth at gcc dot gnu dot org
0 siblings, 1 reply; 2+ messages in thread
From: ElGringo at gmx dot at @ 2009-01-15 13:36 UTC (permalink / raw)
To: gcc-bugs
---code---
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
float f(1.0);
// cout << "Value: "; // works with any cout before eval!!
unsigned int i = *reinterpret_cast<unsigned int*>(&f);
cout << hex << i << endl;
cout << sizeof(float) << endl;
cout << sizeof(unsigned int) << endl;
}
--- end code ---
run w/o -O2:
bernhard@xbernhard$ c++ floatmini.cpp -o floatmini
bernhard@xbernhard$ ./floatmini
3f800000
4
4
=> works
with -O2
bernhard@xbernhard$ c++ floatmini.cpp -o floatmini -O2
bernhard@xbernhard$ ./floatmini
8048779
4
4
=> fails
* If codeline 8 is active (see comment), works too with -O2.
* unsigned int& i = reinterpret_cast<unsigned int&>(f);
fails the same way.
Is that line not standard conform?
------------------------------------
bernhard@xbernhard$ c++ -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2
--enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr
--disable-libmudflap --enable-targets=all --enable-checking=release
--build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.2.3 (Debian 4.2.3-2)
--
Summary: evaluation of reinterpret_cast with -O2
Product: gcc
Version: 4.2.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: ElGringo at gmx dot at
GCC build triplet: i486-linux-gnu
GCC host triplet: i486-linux-gnu
GCC target triplet: i486-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38855
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c++/38855] evaluation of reinterpret_cast with -O2
2009-01-15 13:36 [Bug c++/38855] New: evaluation of reinterpret_cast with -O2 ElGringo at gmx dot at
@ 2009-01-15 14:38 ` rguenth at gcc dot gnu dot org
0 siblings, 0 replies; 2+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-01-15 14:38 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from rguenth at gcc dot gnu dot org 2009-01-15 14:37 -------
It is not. You are violating C++ aliasing rules. Use memcpy or a union.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38855
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-01-15 14:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-15 13:36 [Bug c++/38855] New: evaluation of reinterpret_cast with -O2 ElGringo at gmx dot at
2009-01-15 14:38 ` [Bug c++/38855] " rguenth 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).