Skip to content

Commit 791f90d

Browse files
authored
Merge pull request #10257 from Geod24/fixup-pr-10256
[stable] Fixup PR 10256: Properly nest substituted C++ names in N..E merged-on-behalf-of: Nicholas Wilson <[email protected]>
2 parents ef517c4 + 1ac06a4 commit 791f90d

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/dmd/cppmangle.d

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,24 @@ private final class CppMangleVisitor : Visitor
236236
}
237237
}
238238

239-
bool substitute(RootObject p)
239+
/**
240+
* Attempt to perform substitution on `p`
241+
*
242+
* If `p` already appeared in the mangling, it is stored as
243+
* a 'part', and short references in the form of `SX_` can be used.
244+
* Note that `p` can be anything: template declaration, struct declaration,
245+
* class declaration, namespace...
246+
*
247+
* Params:
248+
* p = The object to attempt to substitute
249+
* nested = Whether or not `p` is to be considered nested.
250+
* When `true`, `N` will be prepended before the substitution.
251+
*
252+
* Returns:
253+
* Whether `p` already appeared in the mangling,
254+
* and substitution has been written to `this.buf`.
255+
*/
256+
bool substitute(RootObject p, bool nested = false)
240257
{
241258
//printf("substitute %s\n", p ? p.toChars() : null);
242259
auto i = find(p);
@@ -245,6 +262,8 @@ private final class CppMangleVisitor : Visitor
245262
//printf("\tmatch\n");
246263
/* Sequence is S_, S0_, .., S9_, SA_, ..., SZ_, S10_, ...
247264
*/
265+
if (nested)
266+
buf.writeByte('N');
248267
buf.writeByte('S');
249268
writeSequenceFromIndex(i);
250269
buf.writeByte('_');
@@ -551,8 +570,13 @@ private final class CppMangleVisitor : Visitor
551570
if (TemplateInstance ti = s.isTemplateInstance())
552571
{
553572
bool needsTa = false;
554-
if (substitute(ti.tempdecl))
573+
const isNested = !!ti.tempdecl.namespace || !!getQualifier(ti.tempdecl);
574+
if (substitute(ti.tempdecl, !haveNE && isNested))
575+
{
555576
template_args(ti);
577+
if (!haveNE && isNested)
578+
buf.writeByte('E');
579+
}
556580
else if (this.writeStdSubstitution(ti, needsTa))
557581
{
558582
if (needsTa)
@@ -812,7 +836,6 @@ private final class CppMangleVisitor : Visitor
812836
isChar((*ti.tiargs)[0]) &&
813837
isChar_traits_char((*ti.tiargs)[1]) &&
814838
isAllocator_char((*ti.tiargs)[2]))
815-
816839
{
817840
buf.writestring("Ss");
818841
return;

test/compilable/cppmangle.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1166,5 +1166,5 @@ version (Posix)
11661166
}
11671167

11681168
extern(C++) void test20094(xvector20094!(V20094)* v);
1169-
static assert(test20094.mangleof == `_Z9test20094PN7ns2009412xvector20094IS0_IhEEE`);
1169+
static assert(test20094.mangleof == `_Z9test20094PN7ns2009412xvector20094INS0_IhEEEE`);
11701170
}

0 commit comments

Comments
 (0)