Article View: gnu.g++.bug
Article #974Re: user-defined conversion used when not needed.
From: Gnanasekaran Swaminathan
Date: Tue, 15 Sep 1992 18:20
Date: Tue, 15 Sep 1992 18:20
48 lines
1796 bytes
1796 bytes
solomon@cs.wisc.edu (Marvin Solomon) writes:
: [gjetost:~/persist/CCversion] cat bug.c
: // Bug in g++ 2.2.2.
: // The call f(d) can be resolved either by
: // Derived -> Derived& (trivial, ARM 13.2, p318)
: // -> Base& (standard conversion 4.7)
Standard conversion applies only to accessible base classes
(ARM 4.7, p38).
: // or by
: // Derived -> Base& (user-defined convertion Derived::operator Base&())
: // According to ARM 13.2, p. 318, paragraph [3]
: // "Of sequences not mentined in [2], those with only standard and
: // trivial conversions are better than all others."
: // Thus the user-defined conversion should not be used.
:
: extern "C" void printf(...);
:
: class Base {
: public:
: int i;
: Base(int ii) : i(ii) {};
: };
:
: class Derived : private Base {
: public:
: Derived(int ii) : Base(ii) {}
: operator Base&();
: };
:
: Derived::operator Base&() {
: printf("Derived %d -> Base\n", i);
: Base *b = new Base(100*i);
: return *b;
: }
:
: void f(Base &b) {
: printf("f(%d)\n",b.i);
: }
:
: main() {
: Derived d(99);
: f(d);
Base of d is not accessible to f(Base&) and hence, it uses
the user defined conversion.
Technical Details
Message-ID:
<1992Sep15.182051.24221@murdoch.acc.Virginia.EDU>Path:
arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!wupost!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!virginia.edu!gs4tReferences:
<9209141440.AA22879@gjetost.cs.wisc.edu>Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!wupost!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!virginia.edu!gs4t From: gs4t@virginia.edu (Gnanasekaran Swaminathan) Subject: Re: user-defined conversion used when not needed. Message-ID: <1992Sep15.182051.24221@murdoch.acc.Virginia.EDU> Sender: gnulists@ai.mit.edu Reply-To: gs4t@virginia.edu (Gnanasekaran Swaminathan) Organization: University of Virginia References: <9209141440.AA22879@gjetost.cs.wisc.edu> Distribution: gnu Date: Tue, 15 Sep 1992 18:20:51 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 50