public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: lindahlb@hotmail.com
To: gcc-gnats@gcc.gnu.org
Cc: unifex@yuidesigns.net, lindahlb@hotmail.com
Subject: c++/7135: Faulty Operator Precedence
Date: Wed, 26 Jun 2002 17:46:00 -0000	[thread overview]
Message-ID: <20020626233316.31020.qmail@sources.redhat.com> (raw)


>Number:         7135
>Category:       c++
>Synopsis:       Faulty Operator Precedence
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Wed Jun 26 16:36:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Brian Lindahl
>Release:        2.95.3
>Organization:
>Environment:
FreeBSD
>Description:
The source code depicting the problem is attatched as a file.

Lines which show existance of the bug:
cout << a.set(5).get() << a.set(30).get();
cout << a.get();

The output of the compiled program:
5305

The machine code appears to be executeing 'set(5)' first, and then 'set(30)', as it should. However, as indicated by the last output, it executed 'set(5)' last as well as first. It appears to be executing 'set(5)' twice.

The generated code should be of the following:
operator<<(operator<<(cout, a.set(5).get()), a.set(30).get());

I ran over the output and code several times to figure out what order the operations are actually taking place, but I was unable to come up with a logical order that would produce the output, unless 'set(5)' was being executed twice.
>How-To-Repeat:
The file attatched shows how to repeat.
>Fix:
There are two fixes:
1) Adjust the problem lines as so:
cout << a.set(5).get();
cout << a.set(30).get();
cout << a.get();
2) Inline the methods 'set(int)' and 'get()'

Apply either fix and the output of the compiled program is as expected:
53030
>Release-Note:
>Audit-Trail:
>Unformatted:


             reply	other threads:[~2002-06-26 23:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-26 17:46 lindahlb [this message]
2002-06-27  5:00 nathan
2002-06-27 13:16 Brian Lindahl
2002-06-30  2:56 nathan
2002-06-30  2:57 Nathan Sidwell

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=20020626233316.31020.qmail@sources.redhat.com \
    --to=lindahlb@hotmail.com \
    --cc=gcc-gnats@gcc.gnu.org \
    --cc=unifex@yuidesigns.net \
    /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: link
Be 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).