This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: return void from void function is allowed.



On Oct 31, 2006, at 12:49 PM, Igor Bukanov wrote:


---------- Forwarded message ----------
From: Igor Bukanov <igor.bukanov@gmail.com>
Date: Oct 31, 2006 9:48 PM
Subject: Re: return void from void function is allowed.
To: Mike Stump <mrs@apple.com>


On 10/31/06, Mike Stump <mrs@apple.com> wrote:

This is valid in C++.

My copy of 1997 C++ public draft contains:


6.6.3 The return statement
...
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 value
type void, a constructor (_class.ctor_), or a destructor
(_class.dtor_). A return statement with an expression can be used
only in functions returning a value; the value of the expression is
returned to the caller of the function. If required, the expression
is implicitly converted to the return type of the function in which it
appears. A return statement can involve the construction and copy of
a temporary object (_class.temporary_). 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.


My reading of that is C++ does not allow return void-expression from
void function. Was it changed later?

Yes, it was:


[stmt.return] 6.6.3 The return statement
...
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). A return statement with an
expression of non-void type can be used only in functions returning a value; the value of the expression is
returned to the caller of the function. The expression is implicitly converted to the return type of the func-
tion in which it appears. A return statement can involve the construction and copy of a temporary object
(12.2). 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.


3 A return statement with an expression of type “cv void”can be used only in functions with a return type
of cv void; the expression is evaluated just before the function returns to its caller.


And final thought, wrong mailing list... gcc-help would have been
better.

I thought bugs in GCC can be discussed here. Sorry if it is a wrong assumption.

Regards, Igor


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]