Bug 4176 – Link error in switch with 4 or more cases and no default

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
Other
OS
Windows
Creation time
2010-05-11T14:50:59Z
Last change time
2017-10-25T03:04:16Z
Keywords
link-failure
Assigned to
No Owner
Creator
Don

Comments

Comment #0 by clugdbug — 2010-05-11T14:50:59Z
void bug4176(int x) { switch(x){ case 1: .. case 4: break; } } ================ OPTLINK (R) for Win32 Release 8.00.1 Copyright (C) Digital Mars 1989-2004 All rights reserved. OPTLINK : Warning 23: No Stack arr.obj(arr) Error 42: Symbol Undefined __d_switch_error --- errorlevel 1 ================ Doesn't happen if the range is "case 1: .. case 3:" or if you add a "default:"
Comment #1 by clugdbug — 2010-05-12T12:43:13Z
Actually it doesn't need case range. It happens even on prehistoric releases of DMD (I tested DMD 0.140). void bug4176(int x) { switch(x) { case 1: case 2: case 3: case 4: break; } } If you compile with -w, you get a "no default" warning, so it doesn't reach the linker.
Comment #2 by andrej.mitrovich — 2011-04-19T08:48:36Z
This error only happens if you're missing the 'main' function. The most recent Optlink version gives these errors: OPTLINK : Warning 23: No Stack errorswitch.obj(errorswitch) Error 42: Symbol Undefined __d_switch_error OPTLINK : Warning 134: No Start Address --- errorlevel 1 Not sure why the error about the switch is there, but it certainly won't link without main, so there's no damage done here right?
Comment #3 by bugzilla — 2017-10-25T03:04:16Z
What's happening is __d_switch_error is in phobos.lib. Phobos.lib is not automatically linked in unless there's a "main" definition in the file. Hence __d_switch_error is undefined. __d_switch_error is what is called when there isn't a default. In any case, now this error message is emitted: test.d(2): Error: switch statement without a default; use final switch or add default: assert(0); or add default: break;