Our template emission strategy is broken

Iain Buclaw via Digitalmars-d digitalmars-d at puremagic.com
Wed Nov 11 23:45:38 PST 2015


On 12 Nov 2015 7:15 am, "Walter Bright via Digitalmars-d" <
digitalmars-d at puremagic.com> wrote:
>
> On 11/11/2015 4:16 PM, Iain Buclaw via Digitalmars-d wrote:
>>
>> The main problem for seamless support is having some way to generate the
C++
>> typeinfo in D to allow work across boundaries.
>
>
> I suspect that is unnecessary.
>
> The whole point of D's C++ interface is to interface with C++ code.
Defining C++ classes in D code that does not link to any C++ code that also
defines those classes won't be supported. I.e. we can reply on the C++ code
generating the necessary C++ typeinfo. The generated D code only has to
link to it, i.e. generate an extern reference to the name of the typeinfo.
>
> Similarly, we never need to throw a C++ exception from D code. All we
need to do is call a library function written in C++ that throws it for us.
>

Yes, never throw a C++ exception from D, even if we manage to intercept the
object.

> What D does need to do is support catching an std::exception*, or a class
derived from std::exception. I believe we are on solid ground in not
supporting any other C++ types being thrown.
>
> Nor do I believe we need to catch C++ objects with catch(...). Catching
C++ objects will need an explicit catch(std.exception*).
>

Well, as demonstrated, that is the one thing that can be supported now for
free.  Either by allowing C++-style catch-all or using language specific
catch-all class matching.

> Over time, perhaps it may become apparent that we do need to support more
kinds of C++ types being thrown. But it is not necessary to get this lead
brick airborne, and we shouldn't waste time worrying about it.
>

Any type could be caught, again I demonstrated this, but I would have more
confidence if g++ generated the typeinfo bindings for us using
pragma(mangle) to some D-friendly symbol.  Rather than us pushing in more
frail mangling support from our end.

--
Regards,
Iain
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20151112/066994c3/attachment.html>


More information about the Digitalmars-d mailing list