Topic: Defect Report: Unclear suppression of standard conversions while binding references to lvalue
Author: Bronek Kozicki <brok@rubikon.pl>
Date: Sun, 14 Sep 2003 14:45:14 +0000 (UTC) Raw View
[ forwarded to C++ Committee. -sdc ]
In section 8.5.3 [dcl.init.ref], paragraph 5, there is following note:
>>>>> citation of existing wording of note
Note: the usual lvalue-to-rvalue (4.1), array-to-pointer (4.2), and
function-to-pointer (4.3) standard conversions are not needed, and
therefore are suppressed, when such direct bindings to lvalues are done.
>>>>> end
I believe that this note is misleading. There should be either:
- no note, and leave this issue to be explained in section 4 only
- explicit list of all suppressed conversions (including pointer
qualification conversion, as covered in section 4.4)
- reminder that result of all standard conversions is never an lvalue,
thus these conversions are suppressed when binding reference to lvalue
The problem:
1. under current wording it's unclear if following code is legal, or
not:
int main()
{
const int ci = 10;
int * pi = NULL;
const int * & rpci = pi;
rpci = &ci;
*pi = 12; // circumvent constness of "ci"
}
2. it is also unclear what behaviour should following program expose:
int main()
{
int * pi = NULL;
const int * const & rcpci = pi; // 1
int i = 0;
pi = &i; // 2
if (pi == rcpci)
std::cout << "bound to lvalue" << std::endl;
else
std::cout << "bound to temporary rvalue" << std::endl;
}
There has been discussion on this issue on comp.lang.c++.moderated month
ago, see
http://groups.google.pl/groups?threadm=9bed99bb.0308041153.1c79e882%40posting.google.com
and there seems to be some confusion about it. I understand that note is
not normative, but apparently even some compiler writers are misled (try
above code snippets on few different compilers, and using different
compilation options - notably GCC 3.2.3 with -Wall -pedantic), thus it
should be cleared up.
My proposal is to change wording of discussed note to:
>>>>> proposed new wording of note
Note: result of every standard conversion is never an lvalue, and
therefore all standard conversions (clause 4) are suppressed, when such
direct bindings to lvalues are done.
>>>>> end
Kind regards
B.Kozicki
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]