C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

cast

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Jean-Marc Bourguet
Guest





PostPosted: Sat Oct 02, 2004 4:55 am    Post subject: cast Reply with quote




In the following code

struct C {
operator char const*() const;
};

void f(char*);
void g(C x) {
f((char*)(x));
f(const_cast<char*>(static_cast<char const*>(x)));
}

Comeau 4.3.3 (web interface), Sun C++ 5.5 Patch 113817-06
2004/01/29 and g++ 3.4.2 all complain about the "C cast".

My reading of 5.4/5 seems to indicate that they should not. Usually
when all the compilers agree against my understanding of the standard,
they are correct, so I wonder what clause did I misread or forget.

Yours,

--
Jean-Marc

---
[ 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 ]

Back to top
Tom Widmer
Guest





PostPosted: Tue Oct 05, 2004 3:26 pm    Post subject: Re: cast Reply with quote



On Sat, 2 Oct 2004 04:55:02 GMT, [email]jm (AT) bourguet (DOT) org[/email] (Jean-Marc Bourguet)
wrote:

Quote:

In the following code

struct C {
operator char const*() const;
};

void f(char*);
void g(C x) {
f((char*)(x));
f(const_cast<char*>(static_cast<char const*>(x)));
}

Comeau 4.3.3 (web interface), Sun C++ 5.5 Patch 113817-06
2004/01/29 and g++ 3.4.2 all complain about the "C cast".

My reading of 5.4/5 seems to indicate that they should not. Usually
when all the compilers agree against my understanding of the standard,
they are correct, so I wonder what clause did I misread or forget.

I think the relevent clause is 13.3.1.5/1. Basically, operator char
const* is not considered a viable function when the target is char*,
since char const* cannot be converted to char* via a standard
conversion sequence.

Tom

---
[ 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 ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.