public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/4337: c++ ignores cast operator
@ 2002-02-26 14:03 nathan
  0 siblings, 0 replies; 2+ messages in thread
From: nathan @ 2002-02-26 14:03 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, nobody, serge.bogdanov

Synopsis: c++ ignores cast operator

State-Changed-From-To: open->analyzed
State-Changed-By: nathan
State-Changed-When: Tue Feb 26 13:57:43 2002
State-Changed-Why:
    confirmed

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=4337


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

* c++/4337: c++ ignores cast operator
@ 2001-09-17 12:06 serge.bogdanov
  0 siblings, 0 replies; 2+ messages in thread
From: serge.bogdanov @ 2001-09-17 12:06 UTC (permalink / raw)
  To: gcc-gnats

>Number:         4337
>Category:       c++
>Synopsis:       c++ ignores cast operator
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Sep 17 12:06:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     intel
>Release:        3.0.0 and 3.0.1
>Organization:
>Environment:

>Description:

In the code below the cast 'a1 = (A1)a2' should be resolved
through the explicit cast operator 'A2::operator A1(). 
The compiler silently ignores it and uses the path 
downcasting A2 to A and using the 'A1(const A &)' 
constructor.

If you remove the explicit casting (A1), it will complain
about an ambiguous conversion which I belive is wrong since
the explicit cast operator exixts:

a.cpp: In function `int main()':
a.cpp:26: warning: choosing `A2::operator A1()' over `A1::A1(const A&)'
a.cpp:26: warning:   for conversion from `A2' to `A1'
a.cpp:26: warning:   because conversion sequence for the argument is better

###################

#include <iostream.h>

struct A {
};
struct A1 : public A {

    A1(const A &) {
	cout << "A1(const A &)" << endl;
    }
    A1() {
	cout << "A1()" << endl;
    }
};
A1	X;
struct A2 : public A {
    operator A1() {
	cout << "operator A1()" << endl;
	return X;
    }
};

int main()
{
    A2 a2;
    A1 a1;
    a1 = (A1)a2;
}
>How-To-Repeat:
> g++ -o a a.cpp -Wall
> a

A1()
A1()
operator A1()
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


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

end of thread, other threads:[~2002-02-26 21:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-26 14:03 c++/4337: c++ ignores cast operator nathan
  -- strict thread matches above, loose matches on Subject: below --
2001-09-17 12:06 serge.bogdanov

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).