Thread View: comp.std.c++
1 messages
1 total messages
Started by Greg McGary
Tue, 21 Nov 1995 02:56
insidious implicit conversions for ref initialization
Author: Greg McGary
Date: Tue, 21 Nov 1995 02:56
Date: Tue, 21 Nov 1995 02:56
30 lines
1690 bytes
1690 bytes
I've read through [conv](4) and [dcl.init.ref](6,7) of the September WP and convinced myself that the following code is conformant: char c = 'a'; double d = 3.14159; char const& cr = d; // binds cr to a temporary holding '\x03' double const& dr = c; // binds dr to a temporary holding 97.0 This seems wrong to me. I'm curious about the history and reasoning behind these rules (particularly [dcl.init.ref](7)). Why is the type checking system so lax here? I can understand why implicit conversions are desirable among builtin arithmetic types for rvalues, but not for lvalues. C++ won't let me apply implicit conversions when seating a pointer type, e.g., char c = 'a'; double d = 3.14159; char const* cp = &d; // error double const* dp = &c; // error I would expect the rules for implicit conversions of references (lvalues) to match the more restrictive rules for pointers, rather than the less restrictive rules for rvalues. --- [ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu. Contact address: std-c++-request@ncar.ucar.edu. The moderation policy is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads