This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c/3764: Gcc incorrectly complains that a noreturn function returns
- To: rth at gcc dot gnu dot org
- Subject: Re: c/3764: Gcc incorrectly complains that a noreturn function returns
- From: Erik Mouw <J dot A dot K dot Mouw at ITS dot TUDelft dot NL>
- Date: Mon, 23 Jul 2001 10:17:08 +0200
- Cc: gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, nobody at gcc dot gnu dot org
- Organization: Eric Conspiracy Secret Labs
- References: <20010723045818.7148.qmail@sourceware.cygnus.com>
On Mon, Jul 23, 2001 at 04:58:18AM -0000, rth@gcc.gnu.org wrote:
> Synopsis: Gcc incorrectly complains that a noreturn function returns
>
> Responsible-Changed-From-To: unassigned->rth
> Responsible-Changed-By: rth
> Responsible-Changed-When: Sun Jul 22 21:58:17 2001
> Responsible-Changed-Why:
> Mine.
> State-Changed-From-To: open->closed
> State-Changed-By: rth
> State-Changed-When: Sun Jul 22 21:58:17 2001
> State-Changed-Why:
> Not a bug. How can gcc possibly know that a write to a particular
> memory location resets the computer? Either live with the
> warning, or fool the compiler by placing an infinite loop
> at the end of the function.
This is what the manual says:
A few standard library functions, such as `abort' and `exit',
cannot return. GNU CC knows this automatically. Some programs
define their own functions that never return. You can declare them
`noreturn' to tell the compiler this fact.
[sample code]
The `noreturn' keyword tells the compiler to assume that `fatal'
cannot return. It can then optimize without regard to what would
happen if fatal' ever did return. This makes slightly better
code. More importantly, it helps avoid spurious warnings of
uninitialized variables.
The way I read this is that the noreturn attribute tells the compiler
that the function doesn't return. If that's not the way, what is the
use of the noreturn attribute anyway? If the compiler doesn't listen to
the directive, it will never be able to perform optimisations, and the
attribute is useless.
In my opinion this is either a compiler bug, or a documentation bug.
Erik
> http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=3764&database=gcc
--
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
of Electrical Engineering, Faculty of Information Technology and Systems,
Delft University of Technology, PO BOX 5031, 2600 GA Delft, The Netherlands
Phone: +31-15-2783635 Fax: +31-15-2781843 Email: J.A.K.Mouw@its.tudelft.nl
WWW: http://www-ict.its.tudelft.nl/~erik/