Bug 3046 – Segfault with C++ static variable (Linux only)
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2009-06-02T07:01:00Z
Last change time
2015-06-09T01:27:57Z
Keywords
ice-on-invalid-code, patch
Assigned to
nobody
Creator
rsinfu
Comments
Comment #0 by rsinfu — 2009-06-02T07:01:35Z
The compiler segfaults compiling this invalid code:
--------------------
class C
{
extern(C++):
static int var; // C++ variable should be error
}
--------------------
The segfault happend in cpp_mangle_name() (cppmangle.c):
--------------------
FuncDeclaration *fd = s->isFuncDeclaration();
if (fd->isConst()) <-- HERE
buf->writeByte('K');
--------------------
Comment #1 by clugdbug — 2009-06-02T17:24:03Z
I can't reproduce this. It works for me on Windows. Is it Linux only, or is something missing from the test case?
Comment #2 by rsinfu — 2009-06-02T17:39:07Z
(In reply to comment #1)
> I can't reproduce this. It works for me on Windows. Is it Linux only, or is
> something missing from the test case?
It's Linux only. On Linux, C++ name mangling is done by the front end. The front end assumes that extern(C++) is applied only to a function, and segfaults when extern(C++) is applied to a static variable.
On Windows, C++ name mangling is done by the backend, which can deal with C++ variable name mangling.
Comment #3 by clugdbug — 2010-08-11T05:57:15Z
Patch: cpp_mangle.c, cpp_mangle_name(), line 112.
FuncDeclaration *fd = s->isFuncDeclaration();
+ if (!fd)
+ {
+ s->error("cannot be declared as extern(C++)");
+ return;
+ }
if (fd->isConst())
buf->writeByte('K');