Bug 1254 – Using a parameter initialized to void in a compile-time evaluated function doesn't work

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2007-06-02T12:28:00Z
Last change time
2014-02-16T15:22:23Z
Keywords
diagnostic, rejects-valid
Assigned to
bugzilla
Creator
matti.niemenmaa+dbugzilla

Comments

Comment #0 by matti.niemenmaa+dbugzilla — 2007-06-02T12:28:24Z
int foo() { int x = void; return bar(x); } int bar(int dummy) { return 1; } const i = foo(); The above results in "Error: variable x is used before initialization" without a file name or line number. The Functions page at http://www.digitalmars.com/d/function.html says only that use of uninitialized variables can give different results at compile time, but it doesn't disallow it. There are two bugs: first, the error message should have a file name and line number, and second, there should be no error message and the code should compile.
Comment #1 by bugzilla — 2007-06-02T12:52:26Z
The compiler is allowed to issue errors for "use before initialized" problems, although it is not required to detect them. On a pragmatic note, I can't see anything good coming from supporting using the values of uninitialized variables in CTFE. The error message missing file/line info is still a bug, though.
Comment #2 by matti.niemenmaa+dbugzilla — 2007-06-02T13:02:18Z
Well, there's no particular use for it in CTFE, but the thing is that a function may be used both with and without CTFE. In the latter case, not initializing a variable is an optimization (though in this case of a single integer it hardly matters), and may be useful. In the CTFE case, it might as well be initialized anyway, if that's easier: it's a bug to rely on the contents of uninitialized variables anyway.
Comment #3 by bugzilla — 2007-06-23T03:46:26Z
The error message should have the file/line. But the code is erroneous - even though the uninitialized value is eventually unused, it is technically used when passed to bar(), and hence is illegal.
Comment #4 by matti.niemenmaa+dbugzilla — 2007-06-26T14:32:07Z
Error message has a line number in DMD 1.017. Marking as FIXED, as it seems that's all I'll get.