Article View: gnu.g++.bug
Article #955user-defined conversion used when not needed.
From: Marvin Solomon
Date: Mon, 14 Sep 1992 04:40
Date: Mon, 14 Sep 1992 04:40
64 lines
3227 bytes
3227 bytes
[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)
// 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);
}
[gjetost:~/persist/CCversion] g++ -v bug.c
Reading specs from /usr/gnu/lib/gcc-lib/decstation/2.2.2/specs
gcc version 2.2.2
/usr/gnu/lib/gcc-lib/decstation/2.2.2/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__ANSI_COMPAT -DMIPSEL -DR3000 -DSYSTYPE_BSD -D_SYSTYPE_BSD -Dbsd4_2 -Dhost_mips -Dmips -Dultrix -Dunix -D__ANSI_COMPAT -D__MIPSEL__ -D__R3000__ -D__SYSTYPE_BSD__ -D___SYSTYPE_BSD__ -D__bsd4_2__ -D__host_mips__ -D__mips__ -D__ultrix__ -D__unix__ -D__ANSI_COMPAT -D__MIPSEL -D__R3000 -D__SYSTYPE_BSD -D___SYSTYPE_BSD -D__bsd4_2 -D__host_mips -D__mips -D__ultrix -D__unix -D__LANGUAGE_C__ -D__LANGUAGE_C -DLA
NGUAGE_C bug.c /usr/tmp/cca22845.i
GNU CPP version 2.2.2 [AL 1.1, MM 19] DECstation running ultrix
/usr/gnu/lib/gcc-lib/decstation/2.2.2/cc1plus /usr/tmp/cca22845.i -quiet -dumpbase bug.cc -version -o /usr/tmp/cca22845.s
GNU C++ version 2.2.2 [AL 1.1, MM 19] DECstation running ultrix compiled by GNU C version 2.2.2.
as -nocpp -EL -v -o bug.o /usr/tmp/cca22845.s
/usr/lib/cmplrs/cc/as0 -v -G 8 -EL -g0 -O1 /usr/tmp/cca22845.s -o /tmp/ctmaa22856 -t /tmp/ctmsta22856
as0: __4Basei __7Derivedi __opR4Base__7Derived f__FR4Base main
0.0u 0.1s 0:01 8% 63+67k 0+8io 6pf+0w
/usr/lib/cmplrs/cc/as1 -v -G 8 -p0 -EL -g0 -O1 /tmp/ctmaa22856 -o bug.o -t /tmp/ctmsta22856
as1: __4Basei __7Derivedi __opR4Base__7Derived f__FR4Base main
0.0u 0.1s 0:00 17% 91+76k 1+1io 8pf+0w
/usr/gnu/lib/gcc-lib/decstation/2.2.2/mips-tfile -v -o bug.o /usr/tmp/cca22845.s
mips-tfile version 2.2.2 [AL 1.1, MM 19] DECstation running ultrix
/usr/gnu/lib/gcc-lib/decstation/2.2.2/ld -EL /usr/lib/cmplrs/cc/crt0.o -L/usr/gnu/lib/gcc-lib/decstation/2.2.2 -L/usr/lib/cmplrs/cc -L/usr/lib/cmplrs/cc -L/usr/gnu/lib bug.o -lg++ -lgcc -lc -lgcc
[gjetost:~/persist/CCversion] a.out
Derived 99 -> Base
f(9900)
[gjetost:~/persist/CCversion] exit
script done on Mon Sep 14 09:38:10 1992
Technical Details
Message-ID:
<9209141440.AA22879@gjetost.cs.wisc.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cs.wisc.edu!solomonShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cs.wisc.edu!solomon From: solomon@cs.wisc.edu (Marvin Solomon) Subject: user-defined conversion used when not needed. Message-ID: <9209141440.AA22879@gjetost.cs.wisc.edu> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Mon, 14 Sep 1992 04:40:40 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 64