From 4587861677310531220
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,ab08a3e89d74b8d7
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2002-05-15 12:56:01 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!kibo.news.demon.net!news.demon.co.uk!demon!mail2news.demon.co.uk!not-for-mail
From: "Garry Lancaster" <glancaster@ntlworld.com>
Newsgroups: comp.std.c++
Subject: Re: Core Language Active Issue #329
Date: Wed, 15 May 2002 19:55:12 GMT
Organization: ntlworld News Service
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
Message-ID: <CFyE8.1187$SY1.95268@news8-gui.server.ntli.net>
References: <3CD19D55.1050804@mail.com> <x9PA8.1887$9W4.932959@news6-win.server.ntlworld.com> <3CD6A00D.2080502@mail.com> <o5dC8.499$1r.48797@news8-gui.server.ntli.net> <3CD99A77.2040301@mail.com> <L1OC8.11982$xb4.1942040@news6-win.server.ntlworld.com> <3CE005FD.6070400@mail.com>
X-Trace: mail2news.demon.co.uk 1021492518 mail2news:17581 mail2news mail2news.demon.co.uk
X-Complaints-To: abuse@demon.net
X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2615.200
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200
NNTP-Posting-Date: Wed, 15 May 2002 20:28:34 BST
Lines: 62
Xref: archiver1.google.com comp.std.c++:11272

Hyman Rosen:
> Here's an example where the
> suggested change definitely changes the behavior of a
> currently legal program.
>
> //////////////////////////////////////////////////////////////////////////
> #include <algorithm>
> extern "C" int printf(const char *, ...);
>
> template <typename T> struct equal
> { friend bool operator==(const T &l, const T &r) { return l.a == r.a; } };
> template <typename T> struct evil
> { friend void f(const T &) { equal<T>(); } };
>
> struct x
> {
>          int a;
>          operator int() const { return a / 10; }
> };
>
> int main()
> {
>          x xs[1] = { { 10 } };
>          x x1 = { 11 };
>          evil<x>();
>          file://f(x1);
>          if (std::find(xs + 0, xs + 1, x1) == xs + 1)
>                  printf("Used operator==(x,x)\n");
>          else
>                  printf("Used operator==(int,int)\n");
> }
> //////////////////////////////////////////////////////////////////////////
>
> Given the proposed change, the program above would
> use operator==(int,int) unless the call to f(x1) was
> uncommented, whereupon it would switch over
> to using operator==(x,x). Under current rules, it would
> always use operator==(x,x).

It's not that simple. For a start, you will have a tough
time finding a compiler with the standard behaviour
(perhaps EDG-based ones?) I tried C++ Builder 5,
Visual C++ 6 and 7 beta 2 and CodeWarrior 5 and
none of them did it the standard way. None of these
four did it the other way you postulated either: even
with the call to f uncommented they still used
op==(int, int)! If I put a call to equal<x>(); in the main
function all except Visual C++ 6 (which produced a
link error) started to call op==(x, x).

Kind regards

Garry Lancaster
Codemill Ltd
Visit our web site at http://www.codemill.net

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



