public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "oder at eleks dot lviv dot ua" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/35835] New: Compiler fails to recognize match of local "extern" declarations Date: Sat, 05 Apr 2008 18:33:00 -0000 [thread overview] Message-ID: <bug-35835-12742@http.gcc.gnu.org/bugzilla/> (raw) Consider following program ======= begin of test.cpp ======== #include <stdio.h> static inline void SetValue(int i) { extern int g_iValue; g_iValue = i; } static inline int GetValue() { extern int g_iValue; return g_iValue; } int g_iValue = 0; int main() { int iValueSave = GetValue(); SetValue(1); printf("%d\n", GetValue()); SetValue(iValueSave); return 0; } ======= end of test.cpp ======== I use this apptoach to only publish get/set global variable accessors in header while keeping variable itself hidden in cpp. If compiled with optimizations turned on, compiler fails identify two local "extern" declarations as a single memory object and uses initial value retrieved for iValueSafe in call to printf as well (as if SetValue() was unrelated to g_iValue). If compiled and run, program outputs 0 instead of 1. osx-leopard:build oder$ g++ -O3 -o test test.cpp osx-leopard:build oder$ ./test 0 Output of "g++ -v" is: Using built-in specs. Target: powerpc-apple-darwin9 Configured with: /var/tmp/gcc/gcc-5478~1/src/configure --disable-checking -enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.0/ --with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/usr/lib --build=powerpc-apple-darwin9 --host=powerpc-apple-darwin9 --target=powerpc-apple-darwin9 Thread model: posix gcc version 4.0.1 (Apple Inc. build 5478) -- Summary: Compiler fails to recognize match of local "extern" declarations Product: gcc Version: 4.0.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: oder at eleks dot lviv dot ua GCC build triplet: ppc GCC host triplet: ppc GCC target triplet: ppc http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35835
next reply other threads:[~2008-04-05 18:33 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2008-04-05 18:33 oder at eleks dot lviv dot ua [this message] 2008-04-05 19:56 ` [Bug c++/35835] " pinskia at gcc dot gnu dot org 2008-04-05 20:02 ` oder at eleks dot lviv dot ua 2008-04-05 20:05 ` [Bug middle-end/35835] " pinskia at gcc dot gnu dot org 2008-04-05 20:59 ` rguenth at gcc dot gnu dot org 2008-04-05 21:16 ` [Bug c++/35835] " pinskia at gcc dot gnu dot org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-35835-12742@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).