Skip to content

Commit

Permalink
Fix issue 20700 - Forward references leads to extern(C++, class|struc…
Browse files Browse the repository at this point in the history
…t) being ignored

On the long run, it looks like we should just move the setScope to AttribDeclaration,
but this is a simple bugfix to target stable.
  • Loading branch information
Geod24 committed Mar 31, 2020
1 parent e18bc4c commit e05468b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/dmd/attrib.d
Expand Up @@ -435,6 +435,13 @@ extern (C++) final class CPPMangleDeclaration : AttribDeclaration
sc.aligndecl, sc.inlining);
}

override void setScope(Scope* sc)
{
if (decl)
Dsymbol.setScope(sc); // for forward reference
return AttribDeclaration.setScope(sc);
}

override const(char)* toChars() const
{
return toString().ptr;
Expand Down
1 change: 1 addition & 0 deletions src/dmd/attrib.h
Expand Up @@ -88,6 +88,7 @@ class CPPMangleDeclaration : public AttribDeclaration

Dsymbol *syntaxCopy(Dsymbol *s);
Scope *newScope(Scope *sc);
void setScope(Scope *sc);
const char *toChars() const;
void accept(Visitor *v) { v->visit(this); }
};
Expand Down
13 changes: 13 additions & 0 deletions test/compilable/cppmangle.d
Expand Up @@ -1251,3 +1251,16 @@ extern(C++, `bar`)
{
void func19542(T)();
}

// https://issues.dlang.org/show_bug.cgi?id=20700
version (Windows)
extern(C++)
{
void test20700_1(const ref Struct200700);
extern(C++, class) struct Struct200700 {}
void test20700_2(const ref Struct200700);

// Note: Needs to be `BV` (`class`), not `BU` (`struct`)
static assert(test20700_1.mangleof == `?test20700_1@@YAXABVStruct200700@@@Z`);
static assert(test20700_2.mangleof == `?test20700_2@@YAXABVStruct200700@@@Z`);
}

0 comments on commit e05468b

Please sign in to comment.