Bug 22604 – Linking against a C++ const array doesn't work

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2021-12-16T19:45:52Z
Last change time
2024-12-13T19:19:55Z
Assigned to
No Owner
Creator
Jan
Moved to GitHub: dmd#18072 →

Comments

Comment #0 by jan — 2021-12-16T19:45:52Z
Using this C++ class: ``` struct Test { __declspec(dllexport) static const int const_vars[2]; __declspec(dllexport) static int nonconst_vars[2]; }; const int Test::const_vars[2] = {11, 23}; int Test::nonconst_vars[2] = {12, 24}; ``` And this D declaration: ``` extern(C++) struct Test { extern export static __gshared const(int)[2] const_vars; extern export static __gshared int[2] nonconst_vars; } ``` You CAN access 'nonconst_vars' just fine, but you CAN'T access 'const_vars'. DMD wants to link against: ?const_vars@Test@@2PAHB which is: public: static int * const Test::const_vars MSVC exports: ?const_vars@Test@@2QBHB which is: public: static int const * const Test::const_vars So far I haven't found a way to work around this, so accessing constant arrays seems to be impossible at the moment.
Comment #1 by nick — 2023-06-24T14:57:30Z
Similar to issue 16359.
Comment #2 by robert.schadek — 2024-12-13T19:19:55Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18072 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB