Bug 14426 – Segfault for missing extern variable

Status
RESOLVED
Resolution
INVALID
Severity
blocker
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2015-04-09T02:10:00Z
Last change time
2015-05-12T11:57:32Z
Assigned to
nobody
Creator
erictsau

Comments

Comment #0 by erictsau — 2015-04-09T02:10:38Z
$ cat test.d extern (C): int i; import std.stdio; void main(){ write(i); } $ dmd -run test --- killed by signal 11 $ rdmd test Segmentation fault (core dumped)
Comment #1 by mxfomin — 2015-05-12T11:57:32Z
That's funny bug. Extern(C): makes 'fall through' effect on main declaration which hijacks druntime main definition, which prevents running module ctors, so some internal data is not initialized properly. This works as expected: import std.stdio; void main(){ writeln(i); } extern (C): int i; According to spec http://dlang.org/attribute.html attribute declaration; // affects the declaration attribute: // affects all declarations until the end of // the current scope declaration; declaration; ... attribute { // affects all declarations in the block declaration; declaration; ... } It seems that it implies file scope, so it works as intended, although it is confusing. Tentatively closed as resolved-invalid.