Topic: Should unary operators convert?
Author: krste@ICSI.Berkeley.EDU ( Krste Asanovic)
Date: 25 Jan 91 03:27:28 GMT Raw View
Should the unary operators *, &, +, -, !, ~ perform user-defined
conversions on their argument?
The following example is rejected by g++ (1.37.2b) and cfront
(2.00.02). I've tried replacing the ~ with +, -, ! and get the same
result. I can't find any indication in ARM that the user-defined
conversion wouldn't be used, surely unary operators are treated the
same as the binary/ternary operators?
class A {
private:
int a;
public:
A(int x) { a = x; };
operator int() { return a; };
};
main()
{
A y(3);
int x;
x = ~y;
}
%g++ -o bug bug.cc
bug.cc: In function int main ():
bug.cc:18: wrong type argument to bit-complement
%CC -o bug bug.cc
CC bug.cc:
1 error
cc -o /tmp_mnt/n/icsib/df/real/krste/tools/g++/library/BitVector/bug -c -I/usr/CC/incl
Author: Bruce.Hoult@bbs.actrix.gen.nz
Date: 29 Jan 91 05:22:55 GMT Raw View
Krste Asanovic writes:
>Should the unary operators *, &, +, -, !, ~ perform user-defined
>conversions on their argument?
>
>The following example is rejected by g++ (1.37.2b) and cfront
>(2.00.02).
Your example is accepted without complaint by Apple's MPW CFront 1.0 (an
AT&T 2.0 compiler). The C code produced is also what you would expect.
--
Bruce.Hoult@bbs.actrix.gen.nz Twisted pair: +64 4 772 116
BIX: brucehoult Last Resort: PO Box 4145 Wellington, NZ
"And they shall beat their swords into plowshares, for if you hit a man
with a plowshare, he's going to know he's been hit."
Author: Seth_Powsner@QM.YCC.Yale.EDU (Seth M Powsner)
Date: 1 Feb 91 21:36:50 GMT Raw View
Seems problematic. Negation - could just as easily convert to float
(double?) as int. A unary bit operator is perhaps a more interesting case.
Seth M Powsner