www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3077] New: crash exiting main() without result code

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

           Summary: crash exiting main() without result code
           Product: D
           Version: unspecified
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: andrei metalanguage.com


int main(string[] args)
{
    try {} catch(Exception) { return 1; }
}

Running this program will cause a segmentation fault. Adding a return 0; at the
end fixes it.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 18 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3077


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com





11:05:23 PDT ---
I get the message:

core.exception.AssertError test.d(4): missing return expression

Is that different from the one you get?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 23 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3077






11:08:15 PDT ---

 I get the message:
 
 core.exception.AssertError test.d(4): missing return expression
 
 Is that different from the one you get?
Compile with -O -release -inline -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 23 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3077


Walter Bright <bugzilla digitalmars.com> changed:

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





13:15:25 PDT ---
If main() was typed to return a void, as a special case then the compiler will
insert a:
   return 0;
statement at the end.

But if a function is typed to return an int, then that's a contract saying the
programmer must put in some sort of return statement. If there is none, the
compiler inserts a:
   assert(0, "missing return expression");
at the end.

If you compile with -w, the compiler will warn you about this. (The compiler
doesn't always do this because it is perfectly legal for a function that is
typed to return an int to never return, such as if it calls abort().)

When compiling in release mode, assert(0) is replaced with a HLT instruction,
which generates a hardware exception at runtime. This is what you're seeing.

It's expected behavior. Not a bug.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 23 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3077


Andrei Alexandrescu <andrei metalanguage.com> changed:

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





15:57:19 PDT ---

 If main() was typed to return a void, as a special case then the compiler will
 insert a:
    return 0;
 statement at the end.
 
 But if a function is typed to return an int, then that's a contract saying the
 programmer must put in some sort of return statement. If there is none, the
 compiler inserts a:
    assert(0, "missing return expression");
 at the end.
 
 If you compile with -w, the compiler will warn you about this. (The compiler
 doesn't always do this because it is perfectly legal for a function that is
 typed to return an int to never return, such as if it calls abort().)
 
 When compiling in release mode, assert(0) is replaced with a HLT instruction,
 which generates a hardware exception at runtime. This is what you're seeing.
 
 It's expected behavior. Not a bug.
Thanks for the explanation. It does not do the least in making things better. Bad behavior is bad behavior, period. I am reopening the bug. This is important. It cost me and it could cost anyone precious time. Crashing at runtime without file and line information is the least effective of all ways to signal that the programmer has a bug in the program, by a large margin. Allowing a function to compile without a proper return is unreasonable. The diagnostic and refusal to generate code should not be relegated to -w. That state of affairs originates in the days when dmd's had much worse flow checking so it would signal a lot of false errors. Now dmd has good enough control flow checking to penalize all missing returns with a compile-time error, at the cost of requiring the occasional unnecessary insertion of an unreachable return statement. By this bug report I am requesting to move the "function has no return statement" diagnostic from -w mode to regular mode. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 23 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3077


Koroskin Denis <2korden gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |2korden gmail.com
           Severity|normal                      |enhancement




-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 23 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3077


Walter Bright <bugzilla digitalmars.com> changed:

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





13:39:14 PDT ---
Fixed dmd 2.032

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