Thread overview | ||||||
---|---|---|---|---|---|---|
|
April 19, 2011 [Issue 5862] New: case statement allows runtime values | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=5862 Summary: case statement allows runtime values Product: D Version: D2 Platform: Other OS/Version: Windows Status: NEW Keywords: accepts-invalid Severity: normal Priority: P2 Component: DMD AssignedTo: nobody@puremagic.com ReportedBy: andrej.mitrovich@gmail.com --- Comment #0 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2011-04-19 13:22:50 PDT --- int foo(ref int y) { y = 5; return y; } void main() { int x = 1; int y = 2; switch (x = foo(y)) { case y: // <- should not be allowed writeln("x == y"); default: } assert(x == 5); assert(y == 5); } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
June 19, 2011 [Issue 5862] case statement allows runtime values | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | http://d.puremagic.com/issues/show_bug.cgi?id=5862 --- Comment #2 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2011-06-19 07:26:37 PDT --- I don't really know why it wouldn't be allowed, unless there's some optimization technique that depends on it. However: void main() { int x; int y; switch (x) { case y + 1: break; default: } } Error: variable y cannot be read at compile time Error: case must be a string or an integral constant, not y + 1 Either runtime values are fully supported, or they are not. Some decision has to be made for this if the compiler and TDPL don't agree with each other. Should I open up a new thread in the NGs to discuss this? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
June 19, 2011 [Issue 5862] case statement allows runtime values | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | http://d.puremagic.com/issues/show_bug.cgi?id=5862 bearophile_hugs@eml.cc changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bearophile_hugs@eml.cc --- Comment #3 from bearophile_hugs@eml.cc 2011-06-19 07:28:44 PDT --- I think this is a valid bug. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
June 19, 2011 [Issue 5862] case statement allows runtime values | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | http://d.puremagic.com/issues/show_bug.cgi?id=5862 Stewart Gordon <smjg@iname.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |REOPENED URL| |http://www.digitalmars.com/ | |d/1.0/statement.html#CaseSt | |atement CC| |smjg@iname.com Platform|Other |All Resolution|INVALID | --- Comment #4 from Stewart Gordon <smjg@iname.com> 2011-06-19 10:37:14 PDT --- http://www.digitalmars.com/d/1.0/statement.html#CaseStatement "The case expressions must all evaluate to a constant value or array. They must be implicitly convertible to the type of the switch Expression." http://www.digitalmars.com/d/2.0/statement.html#CaseStatement "The case expressions must all evaluate to a constant value or array, or a runtime initialized const or immutable variable of integral type. They must be implicitly convertible to the type of the switch Expression." Strangely, 1.068 (Win32) correctly rejects the code. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation