This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/10931] [diagnostic] Incorrect "non-lvalue in unary `&'" error for invalid conversion
- From: "timb at bluearc dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 23 May 2003 08:37:54 -0000
- Subject: [Bug c++/10931] [diagnostic] Incorrect "non-lvalue in unary `&'" error for invalid conversion
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=10931
------- Additional Comments From timb@bluearc.com 2003-05-23 08:37 -------
I don't think it is illegal, because the reference is to const unsigned int, not
unsigned int. Looking at [8.5.3/5], the initialiser is an lvalue but the types
are (as you point out) not reference compatible, and the initialiser does not
have a class type; therefore the second top-level case applies: '- Otherwise
the reference shall be to a non-volatile const type', which does hold. The
initialiser is not an rvalue, so the final case applies: 'a temporary of
type "cv1 T1" is created and initialised from the initialiser expression using
the rules for a non-reference copy initialisation (8.5). The reference is then
bound to the temporary.'
In fact, initialising a named reference does work, fortunately providing a
workaround:
const unsigned int& y = x;
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.