Yesterday, I found myself writing code like this:
SomeStruct getSomeStruct()
{
SomeStruct input;
cin >> input.x;
cin >> input.y;
}
<
I find this interesting. With default options used, the following compilers have the following behavior when compiling the GetSomeStruct() function:
Microsoft VC, all versions (since VC6 anyway):
error C4716: 'getSomeStruct' : must return a value
Digital Mars:
Warning 18: implied return of getSomeStruct at closing '}' does not return value
Comeau:
warning: missing return statement at end of non-void function "getSomeStruct"
gcc:
no error or warning
Given the following couple of sentences from the standard (6.6.3 Paragraph 2):
A return statement without an expression can be used only in functions that do not return a value, that is, a function with the return type void, a constructor (12.1), or a destructor (12.4). ... 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.
I would say there's little reason for a compiler not to give an error in this case. Why do so many compilers give only a warning or no diagnostic at all?