This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c++/9440: [3.4 regression] error message about "non-lvalue in unary '&'" when using ?: operator


>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:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]