public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: andrew@andypo.net
To: gcc-gnats@gcc.gnu.org
Subject: c++/9440: [3.4 regression] error message about "non-lvalue in unary '&'" when using ?: operator
Date: Sat, 25 Jan 2003 17:56:00 -0000	[thread overview]
Message-ID: <20030125175510.2404.qmail@sources.redhat.com> (raw)


>Number:         9440
>Category:       c++
>Synopsis:       [3.4 regression] error message about "non-lvalue in unary '&'" when using ?: operator
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Sat Jan 25 17:56:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Andrew Pollard
>Release:        gcc-3.4-20030125
>Organization:
>Environment:
i686-pc-linux-gnu RedHat8.0/PIII
>Description:
I'm not 100% convinced that the following bit of code is well formed, but the error message given is rather confusing (what unary '&' :-)

odd.cxx:
----------------
struct A {
    explicit A(int);
    operator int() const;
    friend A operator+(const A&, const A&);
};

A
bar(bool b, const A& a)
{
    return (b ? (A(1) + a) : a);
}
----------------

% g++34 -c odd.cxx
odd.cxx: In function `A bar(bool, const A&)':
odd.cxx:10: error: non-lvalue in unary `&'

Previous versions of gcc (from gcc-3.4-20030108 and below) compile this fine without any modifications.

If either of

a) remove the implicit 'int()' cast
b) return type of 'operator+' is changed to 'A&'

It also compiles fine.
>How-To-Repeat:

>Fix:
Workaround is not to use the ?: operator, but just

    if (b) {
        return (A(1) + a);
    }
    return (a);
>Release-Note:
>Audit-Trail:
>Unformatted:


             reply	other threads:[~2003-01-25 17:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-25 17:56 andrew [this message]
2003-01-25 18:56 Andrew Pollard
2003-01-28 15:41 bangerth
2003-01-28 18:26 Andrew Pollard
2003-02-15 18:16 Craig Rodrigues
2003-03-04 23:46 jason
2003-03-06  0:45 jason

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=20030125175510.2404.qmail@sources.redhat.com \
    --to=andrew@andypo.net \
    --cc=gcc-gnats@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: 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).