🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Should unary operators convert?

#801
From: 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
Technical Details
Message-ID: <10440@pasteur.Berkeley.EDU>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!sdd.hp.com!ucsd!ucbvax!pasteur!krste

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!sdd.hp.com!ucsd!ucbvax!pasteur!krste
From: krste@ICSI.Berkeley.EDU ( Krste Asanovic)
Newsgroups: comp.std.c++
Subject: Should unary operators convert?
Keywords: unary operator conversions
Message-ID: <10440@pasteur.Berkeley.EDU>
Date: 25 Jan 91 03:27:28 GMT
Sender: news@pasteur.Berkeley.EDU
Organization: International Computer Science Institute, Berkeley, CA
Lines: 34
Originator: krste@icsib13