www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22604] New: Linking against a C++ const array doesn't work

https://issues.dlang.org/show_bug.cgi?id=22604

          Issue ID: 22604
           Summary: Linking against a C++ const array doesn't work
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: jan krassnigg.de

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.

--
Dec 16 2021