[cfe-dev] C++ Language Support Library
Howard Hinnant
hhinnant at apple.com
Mon Nov 10 10:18:36 PST 2008
On Nov 10, 2008, at 12:55 PM, Sebastian Redl wrote:
> The most interesting part of the interoperability is exceptions. We
> can claim to throw "GNUCC++\0" exceptions, and GCC code will be able
> to catch them. But then we really have to match GCC exactly in all
> relevant aspects (object layout, mostly).
I agree that this is a needed feature.
I have a <stdexcept> laying around that will do this. It does not use
std::string internally, so we are free to break abi with gcc's
std::string (e.g. do a short string optimization). However it does
match the layout of gcc's exceptions which do use std::string
internally. It recreates a very limited ref-counted const
std::string, layout compatible with gcc's std::string, non-templated
(char-only), only has c_str() member (plus special members), not
publicly exposed, 55 lines of code in all. All each exception class
exposes publicly is a void*. E.g.:
class logic_error
: public exception
{
private:
void* __imp_;
public:
explicit logic_error(const string&);
explicit logic_error(const char*);
logic_error(const logic_error&) throw();
logic_error& operator=(const logic_error&) throw();
virtual ~logic_error() throw();
virtual const char* what() const throw();
};
Fortunately sizeof(gcc std::string) == sizeof(void*).
-Howard
More information about the cfe-dev
mailing list