 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Jean-Marc Bourguet Guest
|
Posted: Sat Oct 02, 2004 4:55 am Post subject: cast |
|
|
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
|
Posted: Tue Oct 05, 2004 3:26 pm Post subject: Re: cast |
|
|
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 |
|
 |
|
|
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
|
|