c++/9440: [3.4 regression] error message about "non-lvalue in unary '&'" when using ?: operator
andrew@andypo.net
andrew@andypo.net
Sun Jan 26 01:02:00 GMT 2003
>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:
More information about the Gcc-bugs
mailing list