Bug 4283 – (D1 only) static if with dangling else clause

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
All
OS
All
Creation time
2010-06-06T06:34:00Z
Last change time
2012-11-08T09:29:15Z
Keywords
accepts-invalid, pull
Assigned to
nobody
Creator
bearophile_hugs

Attachments

IDFilenameSummaryContent-TypeSize
658patch.diffrearranged parseBlock a bit for better error messagestext/plain2732

Comments

Comment #0 by bearophile_hugs — 2010-06-06T06:34:41Z
This D2 program compiles and runs with v2.046, but the syntax is wrong: template Foo(bool b) { static if (b) enum bool Foo = 1; else } static assert(Foo!(true) == 1); void main() {}
Comment #1 by ellery-newcomer — 2010-06-06T12:15:49Z
Created attachment 658 rearranged parseBlock a bit for better error messages
Comment #2 by ellery-newcomer — 2012-08-12T23:51:08Z
The problem is if parseBlock encounters a rcurly, it consumes nothing. Otherwise, it will consume { decldefs } : decldefs decldefs ; As near as I can tell, consuming nothing serves no purpose in the parser, but it does allow the following: class C{ public } struct S{ static auto } interface F{ extern(C) } union Z{ extern private } class C2{ align }
Comment #3 by k.hara.pg — 2012-10-27T07:34:11Z
https://github.com/D-Programming-Language/dmd/pull/1230 If DeclDefs is required just one declaration but there is no declaration, parseDeclDefs should raise a syntax error. I think my pull request is much simpler than the original patch.
Comment #4 by github-bugzilla — 2012-10-27T08:43:28Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/7f91fe6c8cd379f8f9d2ab92f3dad32791e35624 fix Issue 4283 - static if with dangling else clause https://github.com/D-Programming-Language/dmd/commit/9d7f15ae8135db7e3461efd584d824063572c984 Merge pull request #1230 from 9rnsr/fix4283 Issue 4283 - static if with dangling else clause
Comment #5 by yebblies — 2012-10-27T08:47:21Z
Fixed D2
Comment #6 by k.hara.pg — 2012-11-08T09:29:15Z