Thread overview
[Issue 7232] New: Warning: statement is not reachable has no line number
Jan 05, 2012
Robert Clipsham
Jan 06, 2012
Kenji Hara
Jan 06, 2012
Kenji Hara
Jan 06, 2012
Kenji Hara
Jan 06, 2012
Walter Bright
January 05, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7232

           Summary: Warning: statement is not reachable has no line number
           Product: D
           Version: D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: robert@octarineparrot.com


--- Comment #0 from Robert Clipsham <robert@octarineparrot.com> 2012-01-05 15:52:33 GMT ---
When the following is compiled with -w or -wi, it will give a warning without a line number
----
bool addArticle()
{
    scope(failure) return false;
    return true;
}
----
Tested on dmd 2.057 on OS X 64 and Ubuntu 32.

$ dmd -w test.d
Warning: statement is not reachable

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 06, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7232


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch


--- Comment #1 from Kenji Hara <k.hara.pg@gmail.com> 2012-01-06 08:51:01 PST ---
https://github.com/D-Programming-Language/dmd/pull/610

In addArticle function, dmd translates the body code like follows:

try {
  return true;
}
catch (Throwable __o) {
  return false;
  throw __o;  // #1 rethrow catched exception object
}

The "statement is not reachable" warning is caused by line #1.

After my patch, the translation result would change like follows:

try {
  return true;
}
catch (Throwable __o) {
  return false;   // this statement never fall through next.
                  // so next unreachable rethrowing is implicitly removed.
}

Finally, original warning would never be generated.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 06, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7232



--- Comment #2 from Kenji Hara <k.hara.pg@gmail.com> 2012-01-06 09:03:30 PST ---
Technical note:

Maybe, the original issue by Robert Clipsham is "unreachable scope(failure)
should warn "statement is not reachable" _with line number_.
But today it is technically enhancement. Because:

1. Current D2 dmd does only check Exception throwing possibilities in flow
analysis.
That means Throwable is not the target of the analysis. In above code,

    scope(failure) return false;
    return true;    // (a)

dmd does not consider the statement (a) throws Throwable or not.

2. scope(failure) catches Throwable object and rethrow it. Therefore the
scope(failure) statement is always analysed as *may be reachable*.

From the two reasons, current dmd cannot detect that the `scope(failure) return false;` is not reachable.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 06, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7232



--- Comment #3 from Kenji Hara <k.hara.pg@gmail.com> 2012-01-06 09:21:19 PST ---
Posted bug 7240 as an enhancement.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 06, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7232


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


--- Comment #4 from Walter Bright <bugzilla@digitalmars.com> 2012-01-06 13:30:16 PST ---
https://github.com/D-Programming-Language/dmd/commit/458065293bd4cf990fb99bcd01fc294e7df21c17

https://github.com/D-Programming-Language/dmd/commit/986404479ea9eac7a9caa32be1f92c22a8aee38a

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------