Bug 18449 – dmd allows to compile `extern(C++) class` even though it should be extern(C++) struct; should give error

Status
RESOLVED
Resolution
DUPLICATE
Severity
critical
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Mac OS X
Creation time
2018-02-16T03:48:37Z
Last change time
2019-06-14T06:54:46Z
Assigned to
No Owner
Creator
Timothee Cour

Comments

Comment #0 by timothee.cour2 — 2018-02-16T03:48:37Z
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
Comment #1 by timothee.cour2 — 2018-02-16T21:10:05Z
my bad: forgot to add `virtual ~A();`, closing
Comment #2 by timothee.cour2 — 2018-02-16T21:30:13Z
reopening and changed title to: dmd allows to compile `extern(C++) class` even though it should be extern(C++) struct; should give error is that fixable or fundamentally hard to detect when key method is defined ?
Comment #3 by pro.mathias.lang — 2019-06-14T06:54:46Z
Marking as duplicate of 18845 as the later is better worded *** This issue has been marked as a duplicate of issue 18845 ***