public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/45437]  New: Loses reference during update
@ 2010-08-28  3:12 igodard at pacbell dot net
  2010-08-28  3:34 ` [Bug c++/45437] " pinskia at gcc dot gnu dot org
                   ` (14 more replies)
  0 siblings, 15 replies; 20+ messages in thread
From: igodard at pacbell dot net @ 2010-08-28  3:12 UTC (permalink / raw)
  To: gcc-bugs

This code:
#include <iostream>
struct s{
        s(bool& bb) : i(0), b(bb), j(0) {}
    int i;
    bool& b;
    int j;
    };

bool    f(s s1, s s2, s s3, int k) {
            s3.b = true;
            return false;
            }
int main() {
        bool bz = false;
        s sz(bz);
        sz.b |= f(sz, sz, sz, 3);
        std::cerr << sz.b << "\n";;
        return 0;
        }

prints this:
s3:~/ootbc$ g++ foo.cc
s3:~/ootbc$ a.out
0

It appears that "a |= f()" is being compiled as if it were the same as "a = a |
F", with the compiler free to order the evaluation of a and f() in "a | f()" in
any way it pleases. The order is exposed when f() has a side effect on a.
However, my understanding of "a |= f()" is that it must be evaluated as if it
were:
    bool& c = a;
    bool d = f();
    operator|=(c, d)
That is, the first argument to "|=" is a reference, not a value. Thus, both
arguments (the reference and the function call) must be evaluated *before* "|="
is called and the reference will have already seen the side effect before "|=.


-- 
           Summary: Loses reference during update
           Product: gcc
           Version: 4.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: igodard at pacbell dot net


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45437


^ permalink raw reply	[flat|nested] 20+ messages in thread
[parent not found: <bug-45437-4@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2011-07-09  3:35 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-28  3:12 [Bug c++/45437] New: Loses reference during update igodard at pacbell dot net
2010-08-28  3:34 ` [Bug c++/45437] " pinskia at gcc dot gnu dot org
2010-08-28  4:12 ` igodard at pacbell dot net
2010-08-28  4:15 ` pinskia at gcc dot gnu dot org
2010-08-28  4:32 ` igodard at pacbell dot net
2010-08-28 11:40 ` rguenth at gcc dot gnu dot org
2010-08-28 17:50 ` igodard at pacbell dot net
2010-08-28 23:48 ` redi at gcc dot gnu dot org
2010-08-29  0:55 ` redi at gcc dot gnu dot org
2010-08-29 11:29 ` redi at gcc dot gnu dot org
2010-08-29 18:01 ` igodard at pacbell dot net
2010-08-29 18:24 ` igodard at pacbell dot net
2010-08-29 20:50 ` redi at gcc dot gnu dot org
2010-08-29 22:40 ` redi at gcc dot gnu dot org
2010-08-31  2:20 ` igodard at pacbell dot net
2010-09-02 15:50 ` jason at gcc dot gnu dot org
     [not found] <bug-45437-4@http.gcc.gnu.org/bugzilla/>
2011-03-23  8:47 ` phorgan1 at gmail dot com
2011-07-08 17:57 ` jason at gcc dot gnu.org
2011-07-09  3:34 ` jason at gcc dot gnu.org
2011-07-09  3:35 ` jason at gcc dot gnu.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).