Topic: cast


Author: jm@bourguet.org (Jean-Marc Bourguet)
Date: Sat, 2 Oct 2004 04:55:02 GMT
Raw View
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                       ]





Author: tom_usenet@hotmail.com (Tom Widmer)
Date: Tue, 5 Oct 2004 15:26:32 GMT
Raw View
On Sat,  2 Oct 2004 04:55:02 GMT, jm@bourguet.org (Jean-Marc Bourguet)
wrote:

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