🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

3 total messages Started by Krste Asanovic Fri, 25 Jan 1991 03:27
Should unary operators convert?
#801
Author: Krste Asanovic
Date: Fri, 25 Jan 1991 03:27
34 lines
1322 bytes
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
Re: Should unary operators convert?
#829
Author: Bruce.Hoult
Date: Tue, 29 Jan 1991 05:22
15 lines
1122 bytes
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."
Re: Should unary operators convert?
#807
Author: Seth M Powsner
Date: Fri, 01 Feb 1991 21:36
4 lines
556 bytes
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
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