Bug 18605 – Missing return not detected when labeled continue is used
Status
RESOLVED
Resolution
WORKSFORME
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2018-03-13T15:28:53Z
Last change time
2023-05-09T14:56:21Z
Assigned to
No Owner
Creator
Yuxuan Shui
Comments
Comment #0 by yshuiv7 — 2018-03-13T15:28:53Z
Code example:
auto test(T...)(int t) {
L:foreach(_; T) {
if (t)
continue L;
return 1;
}
new int; // <-- reported as unreachable
}
int _() {
return test!(1,2,3)(1);
}
While in reality the reachability of 'new int' is dependent on parameter 't'.
Comment #1 by yshuiv7 — 2018-03-13T15:40:50Z
This bug is worse than I thought:
auto test(T...)(int t) pure {
L:foreach(_; T) {
if (t)
continue L;
return 1;
}
}
void main() @safe {
import std.stdio : writeln;
writeln(test!(1,2,3)(1));
}
Results in an uninitialized return value in @safe code.
Comment #2 by yshuiv7 — 2018-03-13T15:42:36Z
Reduced a bit more:
auto test(T...)() {
L:foreach(_; T) {
continue L;
return 1;
}
}
void main() @safe {
import std.stdio : writeln;
writeln(test!(1,2,3)());
}
Comment #3 by razvan.nitu1305 — 2023-05-09T14:56:21Z
I cannot reproduce neither of the examples. I get:
test.d(1): Error: function `test.test!(1, 2, 3).test` no `return exp;` or `assert(0);` at end of function
test.d(11): Error: template instance `test.test!(1, 2, 3)` error instantiating
So this seems to have been fixed.