www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1254] New: Using a parameter initialized to void in a compile-time evaluated function doesn't work

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1254

           Summary: Using a parameter initialized to void in a compile-time
                    evaluated function doesn't work
           Product: D
           Version: 1.014
          Platform: PC
               URL: http://www.digitalmars.com/d/function.html
        OS/Version: Windows
            Status: NEW
          Keywords: diagnostic, rejects-valid
          Severity: normal
          Priority: P3
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: deewiant gmail.com


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.


-- 
Jun 02 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1254






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.


-- 
Jun 02 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1254






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.


-- 
Jun 02 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1254






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.


-- 
Jun 23 2007
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1254


deewiant gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED





Error message has a line number in DMD 1.017. Marking as FIXED, as it seems
that's all I'll get.


-- 
Jun 26 2007