The following code is rejected since gcc 3.4.0:
============================================================
struct A
{
A(int);
operator void*() const;
};
template<int> void foo(const A& x) { 0 ? x : (x ? x : 0); }
============================================================
bug.cc: In function `void foo(const A&)':
bug.cc:7: error: non-lvalue in unary `&'
bug.cc:7: error: could not convert `x' to `bool'
The code compiles, if I make foo an ordinary (non-template) function.
The problem is similar to PR 9440. (This is in fact a reduced version
of comment #12, but I moved it here, because the original bug in PR9440
has been fixed already.)
--
Summary: [3.4/4.0 regression] error message about "non-lvalue in
unary '&'" when using ?: operator
Product: gcc
Version: 4.0.0
Status: UNCONFIRMED
Keywords: rejects-valid, monitored
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: reichelt at gcc dot gnu dot org
CC: gcc-bugs at gcc dot gnu dot org,lpadovan at cs dot unibo
dot it
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18464