D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3046 - Segfault with C++ static variable (Linux only)
Summary: Segfault with C++ static variable (Linux only)
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Linux
: P2 normal
Assignee: No Owner
URL:
Keywords: ice-on-invalid-code, patch
Depends on:
Blocks:
 
Reported: 2009-06-02 07:01 UTC by Shin Fujishiro
Modified: 2015-06-09 01:27 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Shin Fujishiro 2009-06-02 07:01:35 UTC
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 Don 2009-06-02 17:24:03 UTC
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 Shin Fujishiro 2009-06-02 17:39:07 UTC
(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 Don 2010-08-11 05:57:15 UTC
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');
Comment 4 Walter Bright 2010-08-28 15:09:43 UTC
http://www.dsource.org/projects/dmd/changeset/647