Summary: Compiling with optimization produces erroneous
                    variable initialization error
           Product: D
           Version: D2
          Platform: All
        OS/Version: Linux
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD

--- Comment #0 from 2012-10-09 17:41:02 PDT ---
import std.algorithm;
import std.range;

void main() {
    auto N2 = sequence!"n"(cast(size_t)1).map!"a";

When compiling with dmd -O (latest git for dmd, druntime, phobos), this
produces the following errors:

/usr/src/d/phobos/std/range.d(4590): Error: variable upper used before set
/usr/src/d/phobos/std/range.d(4590): Error: variable lower used before set

The referenced line of code occurs in this context:

    auto opSlice(size_t lower, size_t upper)
        assert(upper >= lower); // this is line 4590
        auto s = typeof(this)(this._state, this._n + lower);
        return takeExactly(s, upper - lower);

Which makes no sense, because there is nothing wrong with the reference to
upper and lower (they are function parameters). Perhaps the optimizer
inadvertently permuted the order of stuff in a way that caused the contract to
run before the parameters are initialized?

If -O is not specified, the compile is successful. This problem appears to be
independent of whether I specify -m32 or -m64.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to