Summary: isInputRange and isForwardRange declare unused
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
            Blocks: 3960

--- Comment #0 from Stewart Gordon <> 2012-04-26 07:02:21 PDT ---
"It is an error to declare a local variable that is never referred to. Dead
variables, like anachronistic dead code, are just a source of confusion for
maintenance programmers."

However, as Timon Gehr has pointed out on digitalmars.D.learn,
std.range.isInputRange breaks this rule, and I've discovered that
isForwardRange does too.

template isInputRange(R)
    enum bool isInputRange = is(typeof(
        R r = void;       // can define a range object
        if (r.empty) {}   // can test for empty
        r.popFront();     // can invoke popFront()
        auto h = r.front; // can get the front of the range

template isForwardRange(R)
    enum bool isForwardRange = isInputRange!R && is(typeof(
        R r1 = void;
        R r2 =; // can call "save" against a range object

h and r2 are unused variables.  These templates only work at the moment because
of issue 3960.  Fixing that issue would at the moment cause these templates to
always evaluate to false, since the declarations of h and r2 are illegal
because the variables are never referred to.

Possible solutions:

-        auto h = r.front; // can get the front of the range
+        cast(void) r.front; // can get the front of the range

-        R r2 =; // can call "save" against a range object
+        static assert(is(typeof( : R));

If issue 3960 is dealt with by removing the statement from the spec instead,
there is still some support for a warning about it, so it would be still worth
dealing with this in order to avoid such a warning.

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

Reply via email to