On Mon, Apr 30, 2012 at 9:22 AM, Jordi Gutiérrez Hermoso
<jord...@octave.org> wrote:
> 2012/4/30 Michael Goffioul <michael.goffi...@gmail.com>:
>> On Mon, Apr 30, 2012 at 2:00 PM, Jordi Gutiérrez Hermoso
>> <jord...@octave.org> wrote:
>>> On 29 April 2012 19:42, Claudio Freire <klaussfre...@gmail.com> wrote:
>>>> Here[0] is a patch that makes octave-forge build under gcc 4.7 and
>>>> another[1] for openmpi 1.5.
>>>
>>> Thanks. I looked at your modifications, and they mostly seem safe for
>>> earlier versions of gcc. Did 4.7 now decide that no return in non-void
>>> functions is now an error, not just a warning? Is this standard
>>> behaviour? I'm just curious.
>>
>> MSVC has been reporting that kind of error for years. I always have to
>> "fix" these to make code compilable. Personally, I'd indeed consider a
>> non-void function without a return statement as an error.
>
> Sure, of course it should be fixed[1], I'm just curious to know why
> gcc ever allowed this. For example, is it allowed behaviour in C, and
> gcc's C++ implementation inherited this?

It is allowed in both C and C++, it's completely up the compiler how
to handle it.  The -Wreturn-type flags it as a warning for me, gcc
4.1.2.

Language nerd answer:

C90 §6.6.6.4:

If a return statement without an expression is executed, and the value
of the function call is used by the caller, the behavior is undefined.
Reaching the } that terminates a function is equivalent to a return
statement without an expression.

C99/C11 §6.9.1:

If the } that terminates a function is reached, and the value of the
function call is used by the caller, the behavior is undefined.

C++98/C++03/C++11 §6.6.3:

Flowing off the end of a function is equivalent to a return with no
value; this results in undefined behavior in a value-returning
function.

-- 
mike

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Octave-dev mailing list
Octave-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/octave-dev

Reply via email to