Issue 14951 - Win64: Invalid C++ mangling for __gshared pointer variables
Summary: Win64: Invalid C++ mangling for __gshared pointer variables
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Windows
: P1 enhancement
Assignee: No Owner
URL:
Keywords: C++, pull
Depends on:
Blocks:
 
Reported: 2015-08-23 15:37 UTC by Rainer Schuetze
Modified: 2015-09-05 07:42 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Rainer Schuetze 2015-08-23 15:37:48 UTC
Compile this file with the x64 MC compiler:

// testcpp.cpp
class ClassDeclaration
{
};

extern ClassDeclaration* ti2;

class Type
{
public:
	static ClassDeclaration* typeinfovector;
};

ClassDeclaration* foo()
{
	return ti2 ? ti2 : Type::typeinfovector;
}

and link with

// test.d
extern(C++) class ClassDeclaration
{
}

extern(C++) class Type
{
	static __gshared ClassDeclaration typeinfovector;
}

extern(C++) __gshared ClassDeclaration ti2;

extern(C++) ClassDeclaration* foo();

void main()
{
    foo();
}

///////////////////
cl /c testcpp.cpp
dmd -m64 test.d testcpp.obj

test.obj : error LNK2019: unresolved external symbol "class ClassDeclaration * *
 __cdecl foo(void)" (?foo@@YAPEAPEAVClassDeclaration@@XZ) referenced in function
 _Dmain
testcpp.obj : error LNK2019: unresolved external symbol "class ClassDeclaration
* ti2" (?ti2@@3PEAVClassDeclaration@@EA) referenced in function "class ClassDecl
aration * __cdecl foo(void)" (?foo@@YAPEAVClassDeclaration@@XZ)
testcpp.obj : error LNK2019: unresolved external symbol "public: static class Cl
assDeclaration * Type::typeinfovector" (?typeinfovector@Type@@2PEAVClassDeclarat
ion@@EA) referenced in function "class ClassDeclaration * __cdecl foo(void)" (?f
oo@@YAPEAVClassDeclaration@@XZ)

The dmd generated symbols are missing the "E" modifier for the pointer type:

?ti2@@3PEAVClassDeclaration@@A
?typeinfovector@Type@@2PEAVClassDeclaration@@A
Comment 1 Rainer Schuetze 2015-08-23 17:06:52 UTC
https://github.com/D-Programming-Language/dmd/pull/4935
Comment 2 Rainer Schuetze 2015-08-23 17:07:47 UTC
>extern(C++) ClassDeclaration* foo();

This is wrong, should not have the '*':

>extern(C++) ClassDeclaration foo();
Comment 3 github-bugzilla 2015-08-23 18:55:19 UTC
Commit pushed to stable at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/d16e409431c6a73af8f4a92f512de1976f615b51
Merge pull request #4935 from rainers/issue14951

Fix issue 14951 - VC mangling for class reference/pointer
Comment 4 github-bugzilla 2015-08-29 08:02:20 UTC
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/d16e409431c6a73af8f4a92f512de1976f615b51
Merge pull request #4935 from rainers/issue14951
Comment 5 Rainer Schuetze 2015-09-05 07:42:32 UTC
not automatically closed.