digitalmars.D.bugs - [Issue 5862] New: case statement allows runtime values
- d-bugmail puremagic.com (35/35) Apr 19 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5862
- d-bugmail puremagic.com (24/24) Jun 19 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5862
- d-bugmail puremagic.com (10/10) Jun 19 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5862
- d-bugmail puremagic.com (23/23) Jun 19 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5862
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 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: -------
Apr 19 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5862 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: -------
Jun 19 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5862 bearophile_hugs eml.cc changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bearophile_hugs eml.cc I think this is a valid bug. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 19 2011
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 | 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: -------
Jun 19 2011