public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* Re: Function declared returning something returns nothing
  1999-04-30 23:15 Function declared returning something returns nothing Edward_C_Morgan
@ 1999-04-30 23:15 ` Alexandre Oliva
  0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Oliva @ 1999-04-30 23:15 UTC (permalink / raw)
  To: Edward_C_Morgan; +Cc: egcs-bugs

On Apr 22, 1999, Edward_C_Morgan <ecmorgan@lucent.com> wrote:

> My question is: Shouldn't the compiler warned about functions not
> returning anything, or at least not returning what it says it
> returns?

It warns with -Wall.  According to the standard, falling off the end
of a function that does not return void produces undefined
results. (except for main(), that implicitly returns 0)

-- 
Alexandre Oliva http://www.dcc.unicamp.br/~oliva IC-Unicamp, Brasil
{oliva,Alexandre.Oliva}@dcc.unicamp.br  aoliva@{acm.org,computer.org}
oliva@{gnu.org,kaffe.org,{egcs,sourceware}.cygnus.com,samba.org}
*** E-mail about software projects will be forwarded to mailing lists



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Function declared returning something returns nothing
@ 1999-04-30 23:15 Edward_C_Morgan
  1999-04-30 23:15 ` Alexandre Oliva
  0 siblings, 1 reply; 2+ messages in thread
From: Edward_C_Morgan @ 1999-04-30 23:15 UTC (permalink / raw)
  To: egcs-bugs

I ran into something running egcs 1.1.2 (egcs-2.91.66) on sparc-sun-solaris2.5.1

I have a function as follows:

string
foo()
{
    ....
    // Don't return a string
    ...
}

When I call this function up, the compiler dutifully calls up the dtor for the
string that foo returns after it goes out of
scope.  The problem is that since foo didn't really return a string, the dtor
grabs any memory location and performs the
dtor on it.  (In my case it happened to be an adjacent string.)

My question is:  Shouldn't the compiler warned about functions not returning
anything, or at least not returning what it says it returns?

--
=========================================
 Edward C. Morgan
 Email:  ecmorgan@lucent.com
=========================================





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1999-04-30 23:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-04-30 23:15 Function declared returning something returns nothing Edward_C_Morgan
1999-04-30 23:15 ` Alexandre Oliva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).