public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/25355] New: reinterpret_cast<> yields different (and incorrect) results when using -O2
@ 2005-12-11 17:54 jason dot elbaum at gmail dot com
2005-12-11 17:58 ` [Bug c++/25355] " pinskia at gcc dot gnu dot org
0 siblings, 1 reply; 2+ messages in thread
From: jason dot elbaum at gmail dot com @ 2005-12-11 17:54 UTC (permalink / raw)
To: gcc-bugs
The test case:
#include <iostream>
using namespace std;
int main()
{
unsigned int test = 1067320345;
cout << reinterpret_cast<float &>(test) << endl;
cout << "reinterpret_cast<float &>(test): " <<
reinterpret_cast<float &>(test) << endl;
}
When compiled using -g or -O1, the correct output is produced:
1.2345
reinterpret_cast<float &>(test): 1.2345
When compiled using -O2, the first reinterpret_cast<> produces incorrect
results. The actual value produced depends on the OS:
-NaN
reinterpret_cast<float &>(test): 1.2345
I tested this on Solaris 8 and on Linux Redhat WS3, with identical results. My
conclusion is that we're looking at an optimizer bug.
--
Summary: reinterpret_cast<> yields different (and incorrect)
results when using -O2
Product: gcc
Version: 4.0.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: jason dot elbaum at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25355
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c++/25355] reinterpret_cast<> yields different (and incorrect) results when using -O2
2005-12-11 17:54 [Bug c++/25355] New: reinterpret_cast<> yields different (and incorrect) results when using -O2 jason dot elbaum at gmail dot com
@ 2005-12-11 17:58 ` pinskia at gcc dot gnu dot org
0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-12-11 17:58 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gcc dot gnu dot org 2005-12-11 17:58 -------
You are violating C/C++ aliasing rules.
*** This bug has been marked as a duplicate of 21920 ***
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |DUPLICATE
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25355
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-12-11 17:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-11 17:54 [Bug c++/25355] New: reinterpret_cast<> yields different (and incorrect) results when using -O2 jason dot elbaum at gmail dot com
2005-12-11 17:58 ` [Bug c++/25355] " 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).