D issues are now
tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Summary: |
Using a parameter initialized to void in a compile-time evaluated function doesn't work |
Product: |
D
|
Reporter: |
Matti Niemenmaa <matti.niemenmaa+dbugzilla> |
Component: |
dmd | Assignee: |
Walter Bright <bugzilla> |
Status: |
RESOLVED
FIXED
|
Severity: |
normal
|
Keywords: |
diagnostic, rejects-valid |
Priority: |
P3
|
Version: |
D1 (retired) |
Hardware: |
x86 |
OS: |
Windows |
URL: |
http://www.digitalmars.com/d/function.html
|
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
Walter Bright
2007年06月02日 12:52:26 UTC
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
Matti Niemenmaa
2007年06月02日 13:02:18 UTC
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
Walter Bright
2007年06月23日 03:46:26 UTC
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
Matti Niemenmaa
2007年06月26日 14:32:07 UTC
Error message has a line number in DMD 1.017. Marking as FIXED, as it seems that's all I'll get.