Bug 8795 – mixing in "switch" or "interface;" makes dmd segfault
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-10-10T12:46:00Z
Last change time
2013-08-30T02:42:37Z
Keywords
ice, pull
Assigned to
nobody
Creator
nilsbossung
Comments
Comment #0 by nilsbossung — 2012-10-10T12:46:49Z
A) mixing in "switch"
---
cat > test.d <<code
void s() {mixin("switch");}
code
dmd -c -o- test.d
---
test.d(1): Error: found 'EOF' when expecting '('
test.d(1): Error: expression expected, not 'EOF'
test.d(1): Error: found 'EOF' when expecting ')'
test.d(1): Error: found 'EOF' instead of statement
Segmentation fault (core dumped)
---
B) mixing in "interface;"
---
cat > test.d <<code
mixin("interface;");
code
dmd -c -o- test.d
---
test.d(1): Error: anonymous classes not allowed
Segmentation fault (core dumped)
---
Comment #1 by hsteoh — 2013-08-28T22:32:53Z
In (A), the segfault is happening in SwitchStatement::semantic(Scope*) [statement.c:3101], from attempting to dereference a null pointer (body = body->semantic(sc); where body==NULL). Looks like the body is null because it was an invalid switch mixin, but for some reason the compiler didn't catch the syntax error and proceeded to create a SwitchStatement with a NULL body.