public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/39112] New: incorrect value of a static const double class member
@ 2009-02-05 20:26 alexey dot pushkin at mererand dot com
2009-02-05 20:28 ` [Bug c++/39112] " alexey dot pushkin at mererand dot com
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: alexey dot pushkin at mererand dot com @ 2009-02-05 20:26 UTC (permalink / raw)
To: gcc-bugs
there is a class with a static const double member:
struct Foobar{
static const double var;
};
In one translation unit variable 'var' is defined and initialized as 1.0:
const double Foobar::var = 1.0;
When I access Foobar::var from another translation unit, it's value is 0
instead of 1.0 !
Interestingly, the initialization itself works correctly, if I print bytes
at &Foobar::var, they are
00.00.00.00.00.00.f0.3f, however when dereferencing them with '*' I still
get zero !
This code
const char * ptr = (const char *)(&Foobar::var);
for (int i=0; i < 8; ++i){
if (i) fprintf(stderr, ".");
fprintf(stderr, "%.2x", 0xFF & ptr[i]);
}
fprintf(stderr, " => %g : %g\n", Foobar::var, *((double*)ptr));
produces
00.00.00.00.00.00.f0.3f => 0 : 0
instead of
00.00.00.00.00.00.f0.3f => 1 : 1
Attached is a complete example.
>>THIS BUG SHOWS UP WITH OPTIMIZATION LEVELS OTHER THAN -O0<<
With -O0 it works correctly.
Versions tried:
4.4.0 20090110 (i686-linux)
4.4.0 20090201 (i686-linux)
from Mingw-W64 project site
https://sourceforge.net/project/showfiles.php?group_id=202880&package_id=245516
P.S. Intially I reported this bug to Mingw-W64 people
(https://sourceforge.net/tracker2/?func=detail&atid=983354&aid=2567355&group_id=202880),
however they responded that it's a GCC bug that should
be reported here.
============================================================================
Below is the output from g++ -v:
============================================================================
x86_64-pc-mingw32-g++ -O2 -v -save-temps -c -o main.o main.cpp
Using built-in specs.
Target: x86_64-pc-mingw32
Configured with: ../gcc/configure --target=x86_64-pc-mingw32
--prefix=/opt/buildbot/mingw-w64/slave-linux/linux-i386/build/root
--with-sysroot=/opt/buildbot/mingw-w64/slave-linux/linux-i386/build/root
--enable-languages=all,obj-c++ --disable-multilib
Thread model: win32
gcc version 4.4.0 20090201 (experimental) (GCC)
COLLECT_GCC_OPTIONS='-O2' '-v' '-save-temps' '-c' '-o' 'main.o'
'-shared-libgcc' '-mtune=generic'
/usr/local/opt/mingw64/bin/../libexec/gcc/x86_64-pc-mingw32/4.4.0/cc1plus -E
-quiet -v -iprefix
/usr/local/opt/mingw64/bin/../lib/gcc/x86_64-pc-mingw32/4.4.0/ main.cpp
-mtune=generic -O2 -fpch-preprocess -o main.ii
ignoring duplicate directory
"/usr/local/opt/mingw64/bin/../lib/gcc/../../lib/gcc/x86_64-pc-mingw32/4.4.0/../../../../x86_64-pc-mingw32/include/c++/4.4.0"
ignoring duplicate directory
"/usr/local/opt/mingw64/bin/../lib/gcc/../../lib/gcc/x86_64-pc-mingw32/4.4.0/../../../../x86_64-pc-mingw32/include/c++/4.4.0/x86_64-pc-mingw32"
ignoring duplicate directory
"/usr/local/opt/mingw64/bin/../lib/gcc/../../lib/gcc/x86_64-pc-mingw32/4.4.0/../../../../x86_64-pc-mingw32/include/c++/4.4.0/backward"
ignoring nonexistent directory
"/opt/buildbot/mingw-w64/slave-linux/linux-i386/build/root/usr/local/include"
ignoring duplicate directory
"/usr/local/opt/mingw64/bin/../lib/gcc/../../lib/gcc/x86_64-pc-mingw32/4.4.0/include"
ignoring duplicate directory
"/usr/local/opt/mingw64/bin/../lib/gcc/../../lib/gcc/x86_64-pc-mingw32/4.4.0/include-fixed"
ignoring duplicate directory
"/usr/local/opt/mingw64/bin/../lib/gcc/../../lib/gcc/x86_64-pc-mingw32/4.4.0/../../../../x86_64-pc-mingw32/include"
ignoring nonexistent directory
"/opt/buildbot/mingw-w64/slave-linux/linux-i386/build/root/mingw/include64"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/opt/mingw64/bin/../lib/gcc/x86_64-pc-mingw32/4.4.0/../../../../x86_64-pc-mingw32/include/c++/4.4.0
/usr/local/opt/mingw64/bin/../lib/gcc/x86_64-pc-mingw32/4.4.0/../../../../x86_64-pc-mingw32/include/c++/4.4.0/x86_64-pc-mingw32
/usr/local/opt/mingw64/bin/../lib/gcc/x86_64-pc-mingw32/4.4.0/../../../../x86_64-pc-mingw32/include/c++/4.4.0/backward
/usr/local/opt/mingw64/bin/../lib/gcc/x86_64-pc-mingw32/4.4.0/include
/usr/local/opt/mingw64/bin/../lib/gcc/x86_64-pc-mingw32/4.4.0/include-fixed
/usr/local/opt/mingw64/bin/../lib/gcc/x86_64-pc-mingw32/4.4.0/../../../../x86_64-pc-mingw32/include
End of search list.
COLLECT_GCC_OPTIONS='-O2' '-v' '-save-temps' '-c' '-o' 'main.o'
'-shared-libgcc' '-mtune=generic'
/usr/local/opt/mingw64/bin/../libexec/gcc/x86_64-pc-mingw32/4.4.0/cc1plus
-fpreprocessed main.ii -quiet -dumpbase main.cpp -mtune=generic -auxbase-strip
main.o -O2 -version -o main.s
GNU C++ (GCC) version 4.4.0 20090201 (experimental) (x86_64-pc-mingw32)
compiled by GNU C version 4.3.2 20081105 (Red Hat 4.3.2-7), GMP version
4.2.2, MPFR version 2.3.2.
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: 687eedcb9489aad6b91e300931a51b03
COLLECT_GCC_OPTIONS='-O2' '-v' '-save-temps' '-c' '-o' 'main.o'
'-shared-libgcc' '-mtune=generic'
/usr/local/opt/mingw64/bin/../lib/gcc/x86_64-pc-mingw32/4.4.0/../../../../x86_64-pc-mingw32/bin/as
-o main.o main.s
COMPILER_PATH=/usr/local/opt/mingw64/bin/../libexec/gcc/x86_64-pc-mingw32/4.4.0/:/usr/local/opt/mingw64/bin/../libexec/gcc/:/usr/local/opt/mingw64/bin/../lib/gcc/x86_64-pc-mingw32/4.4.0/../../../../x86_64-pc-mingw32/bin/
LIBRARY_PATH=/usr/local/opt/mingw64/bin/../lib/gcc/x86_64-pc-mingw32/4.4.0/:/usr/local/opt/mingw64/bin/../lib/gcc/:/usr/local/opt/mingw64/bin/../lib/gcc/x86_64-pc-mingw32/4.4.0/../../../../x86_64-pc-mingw32/lib/
COLLECT_GCC_OPTIONS='-O2' '-v' '-save-temps' '-c' '-o' 'main.o'
'-shared-libgcc' '-mtune=generic'
x86_64-pc-mingw32-g++ -O2 -v -save-temps -c -o other.o other.cpp
Using built-in specs.
Target: x86_64-pc-mingw32
Configured with: ../gcc/configure --target=x86_64-pc-mingw32
--prefix=/opt/buildbot/mingw-w64/slave-linux/linux-i386/build/root
--with-sysroot=/opt/buildbot/mingw-w64/slave-linux/linux-i386/build/root
--enable-languages=all,obj-c++ --disable-multilib
Thread model: win32
gcc version 4.4.0 20090201 (experimental) (GCC)
COLLECT_GCC_OPTIONS='-O2' '-v' '-save-temps' '-c' '-o' 'other.o'
'-shared-libgcc' '-mtune=generic'
/usr/local/opt/mingw64/bin/../libexec/gcc/x86_64-pc-mingw32/4.4.0/cc1plus -E
-quiet -v -iprefix
/usr/local/opt/mingw64/bin/../lib/gcc/x86_64-pc-mingw32/4.4.0/ other.cpp
-mtune=generic -O2 -fpch-preprocess -o other.ii
ignoring duplicate directory
"/usr/local/opt/mingw64/bin/../lib/gcc/../../lib/gcc/x86_64-pc-mingw32/4.4.0/../../../../x86_64-pc-mingw32/include/c++/4.4.0"
ignoring duplicate directory
"/usr/local/opt/mingw64/bin/../lib/gcc/../../lib/gcc/x86_64-pc-mingw32/4.4.0/../../../../x86_64-pc-mingw32/include/c++/4.4.0/x86_64-pc-mingw32"
ignoring duplicate directory
"/usr/local/opt/mingw64/bin/../lib/gcc/../../lib/gcc/x86_64-pc-mingw32/4.4.0/../../../../x86_64-pc-mingw32/include/c++/4.4.0/backward"
ignoring nonexistent directory
"/opt/buildbot/mingw-w64/slave-linux/linux-i386/build/root/usr/local/include"
ignoring duplicate directory
"/usr/local/opt/mingw64/bin/../lib/gcc/../../lib/gcc/x86_64-pc-mingw32/4.4.0/include"
ignoring duplicate directory
"/usr/local/opt/mingw64/bin/../lib/gcc/../../lib/gcc/x86_64-pc-mingw32/4.4.0/include-fixed"
ignoring duplicate directory
"/usr/local/opt/mingw64/bin/../lib/gcc/../../lib/gcc/x86_64-pc-mingw32/4.4.0/../../../../x86_64-pc-mingw32/include"
ignoring nonexistent directory
"/opt/buildbot/mingw-w64/slave-linux/linux-i386/build/root/mingw/include64"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/opt/mingw64/bin/../lib/gcc/x86_64-pc-mingw32/4.4.0/../../../../x86_64-pc-mingw32/include/c++/4.4.0
/usr/local/opt/mingw64/bin/../lib/gcc/x86_64-pc-mingw32/4.4.0/../../../../x86_64-pc-mingw32/include/c++/4.4.0/x86_64-pc-mingw32
/usr/local/opt/mingw64/bin/../lib/gcc/x86_64-pc-mingw32/4.4.0/../../../../x86_64-pc-mingw32/include/c++/4.4.0/backward
/usr/local/opt/mingw64/bin/../lib/gcc/x86_64-pc-mingw32/4.4.0/include
/usr/local/opt/mingw64/bin/../lib/gcc/x86_64-pc-mingw32/4.4.0/include-fixed
/usr/local/opt/mingw64/bin/../lib/gcc/x86_64-pc-mingw32/4.4.0/../../../../x86_64-pc-mingw32/include
End of search list.
COLLECT_GCC_OPTIONS='-O2' '-v' '-save-temps' '-c' '-o' 'other.o'
'-shared-libgcc' '-mtune=generic'
/usr/local/opt/mingw64/bin/../libexec/gcc/x86_64-pc-mingw32/4.4.0/cc1plus
-fpreprocessed other.ii -quiet -dumpbase other.cpp -mtune=generic
-auxbase-strip other.o -O2 -version -o other.s
GNU C++ (GCC) version 4.4.0 20090201 (experimental) (x86_64-pc-mingw32)
compiled by GNU C version 4.3.2 20081105 (Red Hat 4.3.2-7), GMP version
4.2.2, MPFR version 2.3.2.
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: 687eedcb9489aad6b91e300931a51b03
COLLECT_GCC_OPTIONS='-O2' '-v' '-save-temps' '-c' '-o' 'other.o'
'-shared-libgcc' '-mtune=generic'
/usr/local/opt/mingw64/bin/../lib/gcc/x86_64-pc-mingw32/4.4.0/../../../../x86_64-pc-mingw32/bin/as
-o other.o other.s
COMPILER_PATH=/usr/local/opt/mingw64/bin/../libexec/gcc/x86_64-pc-mingw32/4.4.0/:/usr/local/opt/mingw64/bin/../libexec/gcc/:/usr/local/opt/mingw64/bin/../lib/gcc/x86_64-pc-mingw32/4.4.0/../../../../x86_64-pc-mingw32/bin/
LIBRARY_PATH=/usr/local/opt/mingw64/bin/../lib/gcc/x86_64-pc-mingw32/4.4.0/:/usr/local/opt/mingw64/bin/../lib/gcc/:/usr/local/opt/mingw64/bin/../lib/gcc/x86_64-pc-mingw32/4.4.0/../../../../x86_64-pc-mingw32/lib/
COLLECT_GCC_OPTIONS='-O2' '-v' '-save-temps' '-c' '-o' 'other.o'
'-shared-libgcc' '-mtune=generic'
x86_64-pc-mingw32-g++ main.o other.o -o a.exe
--
Summary: incorrect value of a static const double class member
Product: gcc
Version: 4.4.0
Status: UNCONFIRMED
Severity: critical
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: alexey dot pushkin at mererand dot com
GCC build triplet: i386-pc-linux (I think)
GCC host triplet: i386-pc-linux
GCC target triplet: x86_64-pc-mingw32
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39112
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/39112] incorrect value of a static const double class member
2009-02-05 20:26 [Bug c++/39112] New: incorrect value of a static const double class member alexey dot pushkin at mererand dot com
@ 2009-02-05 20:28 ` alexey dot pushkin at mererand dot com
2009-02-05 21:59 ` rguenth at gcc dot gnu dot org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: alexey dot pushkin at mererand dot com @ 2009-02-05 20:28 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from alexey dot pushkin at mererand dot com 2009-02-05 20:27 -------
Created an attachment (id=17251)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17251&action=view)
example
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39112
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/39112] incorrect value of a static const double class member
2009-02-05 20:26 [Bug c++/39112] New: incorrect value of a static const double class member alexey dot pushkin at mererand dot com
2009-02-05 20:28 ` [Bug c++/39112] " alexey dot pushkin at mererand dot com
@ 2009-02-05 21:59 ` rguenth at gcc dot gnu dot org
2009-02-05 22:09 ` alexey dot pushkin at mererand dot com
2009-09-01 17:41 ` [Bug target/39112] " ktietz at gcc dot gnu dot org
3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-02-05 21:59 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from rguenth at gcc dot gnu dot org 2009-02-05 21:59 -------
Works for me on i686-linux.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39112
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/39112] incorrect value of a static const double class member
2009-02-05 20:26 [Bug c++/39112] New: incorrect value of a static const double class member alexey dot pushkin at mererand dot com
2009-02-05 20:28 ` [Bug c++/39112] " alexey dot pushkin at mererand dot com
2009-02-05 21:59 ` rguenth at gcc dot gnu dot org
@ 2009-02-05 22:09 ` alexey dot pushkin at mererand dot com
2009-09-01 17:41 ` [Bug target/39112] " ktietz at gcc dot gnu dot org
3 siblings, 0 replies; 5+ messages in thread
From: alexey dot pushkin at mererand dot com @ 2009-02-05 22:09 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from alexey dot pushkin at mererand dot com 2009-02-05 22:08 -------
I believe you are right that it works on x86-linux,
the problem is it doesn't work on x86_64-windows :-(
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39112
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug target/39112] incorrect value of a static const double class member
2009-02-05 20:26 [Bug c++/39112] New: incorrect value of a static const double class member alexey dot pushkin at mererand dot com
` (2 preceding siblings ...)
2009-02-05 22:09 ` alexey dot pushkin at mererand dot com
@ 2009-09-01 17:41 ` ktietz at gcc dot gnu dot org
3 siblings, 0 replies; 5+ messages in thread
From: ktietz at gcc dot gnu dot org @ 2009-09-01 17:41 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from ktietz at gcc dot gnu dot org 2009-09-01 17:40 -------
*** This bug has been marked as a duplicate of 41184 ***
--
ktietz at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |DUPLICATE
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39112
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-09-01 17:41 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-05 20:26 [Bug c++/39112] New: incorrect value of a static const double class member alexey dot pushkin at mererand dot com
2009-02-05 20:28 ` [Bug c++/39112] " alexey dot pushkin at mererand dot com
2009-02-05 21:59 ` rguenth at gcc dot gnu dot org
2009-02-05 22:09 ` alexey dot pushkin at mererand dot com
2009-09-01 17:41 ` [Bug target/39112] " ktietz 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).