Bug 4620 – C++ constructor and template mangling, C++ ABI patch

Status
RESOLVED
Resolution
WONTFIX
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Linux
Creation time
2010-08-11T05:10:46Z
Last change time
2018-06-12T14:03:41Z
Keywords
C++, link-failure, mangling, patch
Assigned to
No Owner
Creator
Matthias Fauconneau
See also
https://issues.dlang.org/show_bug.cgi?id=14086

Attachments

IDFilenameSummaryContent-TypeSize
712test.dDemo: using Qt through native C++ interface (without compiled bindings)application/octet-stream2498
713cpp.patchPatch against r615text/plain3877

Comments

Comment #0 by matthias.fauconneau — 2010-08-11T05:10:46Z
Created attachment 712 Demo: using Qt through native C++ interface (without compiled bindings) --- a/cppmangle.c 2010-08-11 13:28:34.000000000 +0200 +++ b/cppmangle.c 2010-08-11 13:28:34.000000000 +0200 @@ -106,14 +106,36 @@ Dsymbol *p = s->toParent(); if (p && !p->isModule()) { + TemplateInstance *ti = p->isTemplateInstance(); + if(ti) + { + char *name = ti->name->toChars(); + buf->printf("%d%s", strlen(name), name); + buf->writeByte('I'); + for (size_t j = 0; j < ti->tiargs->dim; j++) + { + Object *o = (Object *)ti->tiargs->data[j]; + Type *t = isType(o); + if (t) t->toCppMangle(buf, cms); + } + buf->writeByte('E'); + return; + } + buf->writeByte('N'); FuncDeclaration *fd = s->isFuncDeclaration(); - if (fd->isConst()) + if (fd && fd->isConst()) buf->writeByte('K'); prefix_name(buf, cms, p); - source_name(buf, s); + cms->components.push(s); + if (!strcmp(s->ident->toChars(), "__ctor")) { + buf->writeByte('C'); + buf->writeByte('1'); + } else { + source_name(buf, s); + } buf->writeByte('E'); } @@ -197,10 +219,11 @@ * z ellipsis * u <source-name> # vendor extended type */ - - if (isConst()) + if (isConst()) { + if (cms->substitute(buf, this)) + return; buf->writeByte('K'); - + } switch (ty) { case Tvoid: c = 'v'; break; @@ -320,6 +343,11 @@ void TypeStruct::toCppMangle(OutBuffer *buf, CppMangleState *cms) { + if (isConst()) + { + if ( !cms->substitute(buf, this) ) + buf->writeByte('K'); + } if (!cms->substitute(buf, sym)) cpp_mangle_name(buf, cms, sym); } --- a/expression.c 2010-08-11 13:16:54.000000000 +0200 +++ b/expression.c 2010-08-11 13:16:54.000000000 +0200 @@ -6741,6 +6741,10 @@ e = new DotTemplateExp(loc, av, td); } e = new CallExp(loc, e, arguments); + if (cf && cf->linkage != LINKd) + { //C++ constructor return void + e = new CommaExp(loc, e, new VarExp(loc, tmp)); + } #if !STRUCTTHISREF /* Constructors return a pointer to the instance */ --- a/e2ir.c 2010-08-11 11:51:32.000000000 +0200 +++ b/e2ir.c 2010-08-11 11:51:32.000000000 +0200 @@ -137,7 +137,7 @@ { Parameter *p = Parameter::getNth(tf->parameters, i - j); - if (p->storageClass & (STCout | STCref)) + if (p->storageClass & (STCout | STCref) || (p->type->ty == Tstruct && tf->linkage != LINKd)) { // Convert argument to a pointer, // use AddrExp::toElem() @@ -1733,11 +1733,18 @@ if (member) { // Call constructor ez = callfunc(loc, irs, 1, type, ez, ectype, member, member->type, NULL, arguments); + TypeFunction* tf = (TypeFunction *)(member->type); + if (tf->linkage != LINKd) + { //C++ constructor return void + ez = el_combine(ez, el_same(&ex)); + } #if STRUCTTHISREF - /* Structs return a ref, which gets automatically dereferenced. - * But we want a pointer to the instance. - */ - ez = el_una(OPaddr, TYnptr, ez); + else { + /* Structs return a ref, which gets automatically dereferenced. + * But we want a pointer to the instance. + */ + ez = el_una(OPaddr, TYnptr, ez); + } #endif }
Comment #1 by matthias.fauconneau — 2010-08-11T05:15:03Z
Created attachment 713 Patch against r615
Comment #2 by destructionator — 2011-12-11T10:15:03Z
I'd really like to see something happen with this. Even if it doesn't work for everything, calling more C++ is only a good thing for D.
Comment #3 by wazar.leollone — 2013-05-19T08:24:08Z
PING. This issue is interested for me? Can this feature be merged or this issue is invalid?
Comment #4 by redballoon36 — 2015-03-28T05:30:09Z
It looks like the template mangling has been superceeded by other development. Is the construct part still relevant?
Comment #5 by pro.mathias.lang — 2018-06-12T06:27:46Z
Indeed the code has evolved a lot since then, and C++ interfacing is much easier in D nowadays. Closing as WONTFIX so it doesn't show up in the changelog.
Comment #6 by schveiguy — 2018-06-12T14:03:41Z
(In reply to Mathias LANG from comment #5) > Indeed the code has evolved a lot since then, and C++ interfacing is much > easier in D nowadays. Closing as WONTFIX so it doesn't show up in the > changelog. Just a note: it only shows in the changelog if there is a git log message that references this bug -- all the changelog is auto-generated these days.