D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 11381 - warn/error when static if else ladder has no matching block (or misses "else")
Summary: warn/error when static if else ladder has no matching block (or misses "else")
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-10-29 19:57 UTC by Martin Nowak
Modified: 2024-12-13 18:13 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Martin Nowak 2013-10-29 19:57:05 UTC
static if (T.sizeof == 4) { /*A*/ }
else static if (T.sizeof == 8) { /*B*/ }
else static if (T.sizeof == 12) { /*C*/ }

version (Windows) {}
else version (linux) {}
else version (OSX) {}

static if (something) {}
else version (foo) {}
else static if (somethingelse) {}

----

When such a construct is detected and none of the conditional blocks is matched the compiler should warn/error about an unhandled case.
We could also try to make the declaration of such a ladder without an else-clause a warning/error. This would require an explicit "else {}" to achieve the current behavior and avoids inadvertently missing else clauses similar to how non-final switch statements require a default label.
Comment 1 Andrej Mitrovic 2013-10-30 08:29:58 UTC
A somewhat related ER:

http://d.puremagic.com/issues/show_bug.cgi?id=8433
Comment 2 dlangBugzillaToGithub 2024-12-13 18:13:22 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/17620

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB