From 67163833073110056
X-Google-Thread: f78e5,3738a7440f8f84a8,start
X-Google-Attributes: gidf78e5,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: g2news2.google.com!news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local02.nntp.dca.giganews.com!nntp.speakeasy.net!news.speakeasy.net.POSTED!not-for-mail
NNTP-Posting-Date: Fri, 25 Aug 2006 10:10:43 -0500
Return-Path: <devnull@stump.algebra.com>
X-Authentication-Warning: mulga.csse.unimelb.edu.au: fjh set sender to devnull@stump.algebra.com using -f
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Original-To: std-c++@mailman.ucar.edu
Delivered-To: std-c++@mailman.ucar.edu
From: "Lucian Radu Teodorescu" <Luc.Teodorescu@gmail.com>
Newsgroups: comp.std.c++
Subject: Conversion ambiguity
Organization: http://groups.google.com
Message-ID: <1156491329.387607.256250@74g2000cwt.googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Complaints-To: groups-abuse@google.com
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.6) Gecko/20060728 Firefox/1.5.0.6,gzip(gfe),gzip(gfe)
X-HTTP-Via: 1.1 ISA
Complaints-To: groups-abuse@google.com
Injection-Info: 74g2000cwt.googlegroups.com; posting-host=82.77.120.46;
   posting-account=0ZEmqQ0AAAA5SvBYm460lOS2URy_g1Cy
X-Virus-Scanned: amavisd-new at ucar.edu
X-Virus-Scanned: amavisd-new at csse.unimelb.edu.au
Approved: Fergus Henderson <fjh@cs.mu.oz.au>, moderator of comp.std.c++
X-Virus-Scanned: amavisd-new at csse.unimelb.edu.au
Date: Fri, 25 Aug 2006 10:00:22 CST
Lines: 76
NNTP-Posting-Host: 65.182.171.162
X-Trace: sv3-aMYajc1zcpLA+y0SmZfbYv8WIrTG9c+iD1Qet1lWz7iCPnj5XzRcTTBAHGjseYV3DiSsyg4LJnqkdUS!SErGObAJx4B1HC9SXX42Zif3ykDh+4PYfJDQYw5yGMwz55d25bUN7g8kg3m+x1OGAHM9G7FUzEHk!FhU9NaxurlpGK55AUF2hqPCCoDxTOIUkmdQvMIVD4g==
X-Complaints-To: abuse@speakeasy.net
X-DMCA-Complaints-To: abuse@speakeasy.net
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.32
Xref: g2news2.google.com comp.std.c++:3515

Hello

I've posted this message alson on comp.lang.c++.moderated, but it seems
that we have blocked there, as we need an C++ expert on overloading to
make things clear, and none responded there. We decided to seek here
for help.

You can find the original post (with some debates) here:
http://groups.google.com/group/comp.lang.c++.moderated/browse_frm/thread/d7a9a97c5276ec64

Basically we have the following code:

#include <iostream>
using namespace std;

struct Target;
struct Source;

struct Target
{
    Target() {}

    Target(const Source& other)
    {
        cout << "Target: conversion constructor" << endl;
    }

};

struct Source
{
    Source() {}

    operator Target () // Note, no const here
    {
        cout << "Source: conversion operator" << endl;
        return Target();
    }

};

int main(int argc, char* argv[])
{
    Target t;
    Source s;

    t = s;

    return 0;

}

We failed to decide if this code is legal in C++. Different compiler
give different results. For example MSVC++ 8.0 fails to compile this
(in both cases where the conversion operator is non-const and const),
and GCC 3.4.3 will always compile the given code, no matter if the
conversion operator is const or not. (If the conversion operator is not
const, the conversion operator will get called, and if it is const, the
conversion constructor will be called).

The questions are:
1. Should the above code compile?
2. If yes, what is the result?
3. If the conversion function is const, should the code compile?
4. If the conversion function is const and the code compiles, what is
the result?

Thank you,
Lucian Radu Teodorescu

---
[ 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.comeaucomputing.com/csc/faq.html                      ]



