🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2646

insidious implicit conversions for ref initialization

#2646
From: Greg McGary
Date: Tue, 21 Nov 1995 02:56
30 lines
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. ]
Technical Details
Message-ID: <m0tHc4N-0005fwC@magilla.magilla.cichlid.com>
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
Date: 21 Nov 95 02:56:46 GMT
Approved: fjh@cs.mu.oz.au
Organization: -
Newsgroups: comp.std.c++
Message-ID: <m0tHc4N-0005fwC@magilla.magilla.cichlid.com>
X-Original-Date: Mon, 20 Nov 95 14:39 EST
From: Greg McGary <gkm@magilla.cichlid.com>
Subject: insidious implicit conversions for ref initialization
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMLFAC+EDnX0m9pzZAQHcpQGAi5AWYbiRKmQoshAaLs62eM5+T18IWaGq
 FkbyYgDI3kE3NH4+IJV9R3bmrm6sXPM1
 =Yqqk