public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Problem with overloaded function selection
@ 2002-08-12  3:22 Andrey Pozdeev
  0 siblings, 0 replies; 6+ messages in thread
From: Andrey Pozdeev @ 2002-08-12  3:22 UTC (permalink / raw)
  To: gcc-help

I tried to compile the following example using GCC and MS Visual C++:
-----------
class A
{
    public:
    A(){};
};

class B
{
    public:
    operator double() {return 0L;};
    operator int() { return 0; };
    operator A() { return A();};
};


void test(char){};
void test(A){};

int main()
{
  B b;
  test(b);
  return 0;
}
-------------
Both compilers compiles this example succesfully.
But if we comment line with 'operator double' or with 'operator int' then GCC 
will complain, Visual C++ will not.

What's the matter ?

Andrey.
----
  http://www.rambler.ru

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Problem with overloaded function selection
  2002-08-12  7:07 ` Rupert Wood
@ 2002-08-12  7:13   ` bjorn rohde jensen
  0 siblings, 0 replies; 6+ messages in thread
From: bjorn rohde jensen @ 2002-08-12  7:13 UTC (permalink / raw)
  To: Rupert Wood; +Cc: 'Andrey Pozdeev', gcc-help

Hi Rupert,

 Rupert Wood wrote:
> 
>     void test(A&) {}
> 
> then the GCC problem goes away. I guess the copy construction counts as
> a second conversion.

 Is that not just ordinary polymorphism through references,
that is conversion of reference to derived to reference to
base class?

Yours sincerely,

Bjorn

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: Problem with overloaded function selection
       [not found] <616BE6A276E3714788D2AC35C40CD18D780D92@whale.softwire.co.uk>
@ 2002-08-12  7:07 ` Rupert Wood
  2002-08-12  7:13   ` bjorn rohde jensen
  0 siblings, 1 reply; 6+ messages in thread
From: Rupert Wood @ 2002-08-12  7:07 UTC (permalink / raw)
  To: bjensen, 'Andrey Pozdeev'; +Cc: gcc-help

Bjorn Rhode Jensen wrote:

>  I guess, one will have to look in the specs to
> see, who is right in this matter. My gut feeling
> is, that it gcc is right. Conversions and function
> overloading seem pretty othogonal to me. Why should
> two conversions be worse than one conversion in matching
> an overloaded function??

I haven't had a chance to look at the standards either but I did play
with this a little: if you make test accept an A reference instead of an
A object:

    void test(A&) {}

then the GCC problem goes away. I guess the copy construction counts as
a second conversion.

Rup.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Problem with overloaded function selection
  2002-08-12  3:25 Andrey Pozdeev
@ 2002-08-12  7:01 ` bjorn rohde jensen
  0 siblings, 0 replies; 6+ messages in thread
From: bjorn rohde jensen @ 2002-08-12  7:01 UTC (permalink / raw)
  To: Andrey Pozdeev; +Cc: gcc-help

Hi Andrey,

The conversions

>     operator double() {return 0L;};
>     operator int() { return 0; };

 are equally poor, as one level of user defined
conversions and one level of default conversions
are required to match

> void test(char){};

 Having both conversions causes neither to be
considered, which means that

>     operator A() { return A();};

is the only choice.

 Removing either of
>     operator double() {return 0L;};
>     operator int() { return 0; };

 makes the call
>   test(b);

 ambiguous, since
> void test(char){};

is a candidate through one level of user defined
conversions and one level of default conversions
and

> void test(A){};
is a candidate through one level of user defined
conversions.

 I guess, one will have to look in the specs to
see, who is right in this matter. My gut feeling
is, that it gcc is right. Conversions and function
overloading seem pretty othogonal to me. Why should
two conversions be worse than one conversion in matching
an overloaded function??

Yours sincerely,

Bjorn

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Problem with overloaded function selection
@ 2002-08-12  3:25 Andrey Pozdeev
  2002-08-12  7:01 ` bjorn rohde jensen
  0 siblings, 1 reply; 6+ messages in thread
From: Andrey Pozdeev @ 2002-08-12  3:25 UTC (permalink / raw)
  To: gcc-help

I tried to compile the following example using GCC and MS Visual C++:
-----------
class A
{
    public:
    A(){};
};

class B
{
    public:
    operator double() {return 0L;};
    operator int() { return 0; };
    operator A() { return A();};
};


void test(char){};
void test(A){};

int main()
{
  B b;
  test(b);
  return 0;
}
-------------
Both compilers compiles this example succesfully.
But if we comment line with 'operator double' or with 'operator int' then GCC 
will complain, Visual C++ will not.

What's the matter ?

Andrey.
----
  http://www.rambler.ru

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Problem with overloaded function selection
@ 2002-08-12  3:18 Andrey Pozdeev
  0 siblings, 0 replies; 6+ messages in thread
From: Andrey Pozdeev @ 2002-08-12  3:18 UTC (permalink / raw)
  To: gcc-help

I tried to compile the following example using GCC and MS Visual C++:
-----------
class A
{
    public:
    A(){};
};

class B
{
    public:
    operator double() {return 0L;};
    operator int() { return 0; };
    operator A() { return A();};
};


void test(char){};
void test(A){};

int main()
{
  B b;
  test(b);
  return 0;
}
-------------
Both compilers compiles this example succesfully.
But if we comment line with 'operator double' or with 'operator int' then GCC 
will complain, Visual C++ will not.

What's the matter ?

Andrey.
----
  http://www.rambler.ru

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2002-08-12 14:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-12  3:22 Problem with overloaded function selection Andrey Pozdeev
     [not found] <616BE6A276E3714788D2AC35C40CD18D780D92@whale.softwire.co.uk>
2002-08-12  7:07 ` Rupert Wood
2002-08-12  7:13   ` bjorn rohde jensen
  -- strict thread matches above, loose matches on Subject: below --
2002-08-12  3:25 Andrey Pozdeev
2002-08-12  7:01 ` bjorn rohde jensen
2002-08-12  3:18 Andrey Pozdeev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).