www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 252] New: -w and switch returns = compile errors

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

           Summary: -w and switch returns = compile errors
           Product: D
           Version: 0.162
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: diagnostic, rejects-valid
          Severity: minor
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: jpelcis gmail.com


char[] foo (int bar) {
        switch (bar) {
                case 1:
                        return "1";
                case 2:
                        return "2";
                default:
                        return "many";
        }
}


Compiling this gives the following incorrect error message:

C:\programs>dmd -w test.d
warning - test.d(1): function test.foo no return at end of function


Severity is minor because there are at least 3 easy workarounds:

Use if-else.
Assign to a temporary variable and return that outside of the switch.
Place a return immediately after the switch.


-- 
Jul 14 2006
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=252


smjg iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg iname.com
            Summary|-w and switch returns =     |-w and switch returns =
                   |compile errors              |bogus "no return at end of
                   |                            |function" warning




------- Comment #1 from smjg iname.com  2007-02-11 20:04 -------
Probably part of the same bug: If you add a statement after the switch, it
fails to report "statement is not reachable".


-- 
Feb 11 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=252


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |arkangath gmail.com




------- Comment #2 from bugzilla digitalmars.com  2008-07-01 23:21 -------
*** Bug 1169 has been marked as a duplicate of this bug. ***


-- 
Jul 01 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=252


davidl 126.com changed:

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




------- Comment #3 from davidl 126.com  2008-07-02 04:07 -------
seems this code compiles fine in dmd 1.031


-- 
Jul 02 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=252


davidl 126.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|WORKSFORME                  |




------- Comment #4 from davidl 126.com  2008-07-02 04:10 -------
sorry ... it's a warning related issue...reopened


-- 
Jul 02 2008
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=252


bugzilla digitalmars.com changed:

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




------- Comment #5 from bugzilla digitalmars.com  2008-07-09 22:31 -------
Fixed dmd 1.032 and 2.016


-- 
Jul 09 2008