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

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1254 - Using a parameter initialized to void in a compile-time evaluated function doesn't work
Summary: Using a parameter initialized to void in a compile-time evaluated function do...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P3 normal
Assignee: Walter Bright
URL: http://www.digitalmars.com/d/function...
Keywords: diagnostic, rejects-valid
Depends on:
Blocks:
Reported: 2007年06月02日 12:28 UTC by Matti Niemenmaa
Modified: 2014年02月16日 15:22 UTC (History)
0 users

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Matti Niemenmaa 2007年06月02日 12:28:24 UTC
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.


AltStyle によって変換されたページ (->オリジナル) /