www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18449] New: extern(C++) class layout does not work

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

          Issue ID: 18449
           Summary: extern(C++) class layout does not work
           Product: D
           Version: D2
          Hardware: x86
                OS: Mac OS X
            Status: NEW
          Severity: critical
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: timothee.cour2 gmail.com

seems like either a serious bug or did I do something wrong?



```har
--- main3.d
import core.stdc.stdio;

extern(C++) class A{
public:
  int x;
  ~this();
   disable this();
}

extern(C++)
void initialize(A a, int x){
  a.x=x;
  printf("x=%d\n", a.x);
  printf("a=%p\n", cast(void*)a);
  printf("ax=%p\n", cast(void*)(&a.x));
}
--- fun3.cpp
#include <stdio.h>

class A{
public:
  int x;
  ~A();
  A(){x=13;}
};

void initialize(A*a, int x);

A::~A(){
}

int main (int argc, char *argv[]) {

  auto a=new A();
  initialize(a, 100);
  printf("x2:%d\n", a->x);
  printf("a2=%p\n", (void*)a);
  printf("ax2=%p\n", (void*)(&a->x));

  return 0;
}
```


dmd -c main3.d && g++ -o main3 -std=c++11 main3.o fun3.cpp
-Wl,-lphobos2,-L/Users/timothee/homebrew/opt/dmd/lib && ./main3
x=100
a=0x7fd04bc02840
ax=0x7fd04bc02848
x2:13 #BUG: should be 100
a2=0x7fd04bc02840
ax2=0x7fd04bc02840
#BUG: ax2 != ax


DMD64 D Compiler v2.078.1

--
Feb 15 2018