* [PATCH] Fix PR gdb/290
@ 2002-02-09 9:27 kettenis
2002-02-09 11:19 ` Andrew Cagney
0 siblings, 1 reply; 6+ messages in thread
From: kettenis @ 2002-02-09 9:27 UTC (permalink / raw)
To: gdb-patches
Checked in as obvious. Wonder why GCC didn't warn about this. Should
we add some more -Wxxx flags?
Mark
Index: ChangeLog
from Mark Kettenis <kettenis@gnu.org>
* doublest.c (store_typed_floating): Don't try to return a value.
Fixes PR gdb/290.
Index: doublest.c
===================================================================
RCS file: /cvs/src/src/gdb/doublest.c,v
retrieving revision 1.8
diff -u -p -r1.8 doublest.c
--- doublest.c 2002/01/22 19:57:40 1.8
+++ doublest.c 2002/02/09 17:24:44
@@ -732,9 +732,9 @@ store_typed_floating (void *addr, const
memset (addr, 0, TYPE_LENGTH (type));
if (TYPE_FLOATFORMAT (type) == NULL)
- return store_floating (addr, TYPE_LENGTH (type), val);
-
- floatformat_from_doublest (TYPE_FLOATFORMAT (type), &val, addr);
+ store_floating (addr, TYPE_LENGTH (type), val);
+ else
+ floatformat_from_doublest (TYPE_FLOATFORMAT (type), &val, addr);
}
/* Convert a floating-point number of type FROM_TYPE from a
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix PR gdb/290
2002-02-09 9:27 [PATCH] Fix PR gdb/290 kettenis
@ 2002-02-09 11:19 ` Andrew Cagney
2002-02-09 11:37 ` Joe Buck
0 siblings, 1 reply; 6+ messages in thread
From: Andrew Cagney @ 2002-02-09 11:19 UTC (permalink / raw)
To: kettenis, gcc; +Cc: gdb-patches
[added gcc]
> Checked in as obvious. Wonder why GCC didn't warn about this. Should
> we add some more -Wxxx flags?
I was looking at it and wondering the same thing - I know I've fixed
botched return type warnings. Trying:
static int f1 (void) { return 1; }
static void f2 (void) { return 1; }
static void f3 (void) { return; }
static int f4 (void) { return; }
I get:
-Wimplicit -Wreturn-type -Wcomment -Wtrigraphs -Wformat -Wparentheses
-Wpointer-arith -Wuninitialized -Werror
doublest.c: In function `f2':
doublest.c:741: warning: `return' with a value, in function returning void
doublest.c: In function `f4':
doublest.c:743: warning: `return' with no value, in function returning
non-void
so ok so far. Hmm, I think this tells the story:
static void f5 (int a) { return f3(); }
Returning the result from a function that returns void (f3()) doesn't
attract a warning.
Bug or feature?
Andrew
> Mark
>
>
> Index: ChangeLog
> from Mark Kettenis <kettenis@gnu.org>
>
> * doublest.c (store_typed_floating): Don't try to return a value.
> Fixes PR gdb/290.
>
> Index: doublest.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/doublest.c,v
> retrieving revision 1.8
> diff -u -p -r1.8 doublest.c
> --- doublest.c 2002/01/22 19:57:40 1.8
> +++ doublest.c 2002/02/09 17:24:44
> @@ -732,9 +732,9 @@ store_typed_floating (void *addr, const
> memset (addr, 0, TYPE_LENGTH (type));
>
> if (TYPE_FLOATFORMAT (type) == NULL)
> - return store_floating (addr, TYPE_LENGTH (type), val);
> -
> - floatformat_from_doublest (TYPE_FLOATFORMAT (type), &val, addr);
> + store_floating (addr, TYPE_LENGTH (type), val);
> + else
> + floatformat_from_doublest (TYPE_FLOATFORMAT (type), &val, addr);
> }
>
> /* Convert a floating-point number of type FROM_TYPE from a
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix PR gdb/290
2002-02-09 11:19 ` Andrew Cagney
@ 2002-02-09 11:37 ` Joe Buck
2002-02-09 11:51 ` Andrew Cagney
2002-02-09 12:18 ` Andreas Schwab
0 siblings, 2 replies; 6+ messages in thread
From: Joe Buck @ 2002-02-09 11:37 UTC (permalink / raw)
To: Andrew Cagney; +Cc: kettenis, gcc, gdb-patches
Andrew writes:
> static void f3 (void) { return; }
> ...
> so ok so far. Hmm, I think this tells the story:
>
> static void f5 (int a) { return f3(); }
>
> Returning the result from a function that returns void (f3()) doesn't
> attract a warning.
> Bug or feature?
For C++, it is a non-optional feature; the standard requires this to work
correctly (a void function may say "return foop();" if foop's return type
is void). The reason for this will become clear after you write templates
for a while; without it "void" becomes more of an oddball case.
For C89, I don't think it's legal though it may be reasonable to accept
as an extension; I don't know about C99.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix PR gdb/290
2002-02-09 11:37 ` Joe Buck
@ 2002-02-09 11:51 ` Andrew Cagney
2002-02-09 12:18 ` Andreas Schwab
1 sibling, 0 replies; 6+ messages in thread
From: Andrew Cagney @ 2002-02-09 11:51 UTC (permalink / raw)
To: Joe Buck; +Cc: kettenis, gcc, gdb-patches
> For C89, I don't think it's legal though it may be reasonable to accept
> as an extension; I don't know about C99.
More info is at:
http://sources.redhat.com/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gdb&pr=290
It upset Sun's ISO C compiler.
enjoy,
Andrew
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix PR gdb/290
2002-02-09 11:37 ` Joe Buck
2002-02-09 11:51 ` Andrew Cagney
@ 2002-02-09 12:18 ` Andreas Schwab
2002-02-09 17:39 ` Joe Buck
1 sibling, 1 reply; 6+ messages in thread
From: Andreas Schwab @ 2002-02-09 12:18 UTC (permalink / raw)
To: Joe Buck; +Cc: Andrew Cagney, kettenis, gcc, gdb-patches
Joe Buck <jbuck@synopsys.COM> writes:
|> For C89, I don't think it's legal though it may be reasonable to accept
|> as an extension; I don't know about C99.
The C99 standard is quite clear about this:
6.8.6.4[#1] A return statement with an expression shall not appear in
a function whose return type is void. A return statement without an
expression shall only appear in a function whose return type is void.
Andreas.
--
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE GmbH, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix PR gdb/290
2002-02-09 12:18 ` Andreas Schwab
@ 2002-02-09 17:39 ` Joe Buck
0 siblings, 0 replies; 6+ messages in thread
From: Joe Buck @ 2002-02-09 17:39 UTC (permalink / raw)
To: Andreas Schwab; +Cc: Joe Buck, Andrew Cagney, kettenis, gcc, gdb-patches
> Joe Buck <jbuck@synopsys.COM> writes:
>
> |> For C89, I don't think it's legal though it may be reasonable to accept
> |> as an extension; I don't know about C99.
>
> The C99 standard is quite clear about this:
>
> 6.8.6.4[#1] A return statement with an expression shall not appear in
> a function whose return type is void. A return statement without an
> expression shall only appear in a function whose return type is void.
OK, then this can only be done in C++. Any C code should avoid it.
for
void foo();
void bar() { return foo();}
(which is legal C++)
I've just checked, and gcc 2.95.2 and 3.0.3 reject this type of C code
iff -ansi -pedantic is specified. By default they accept it. Anyone
developing code that must compile with many compilers probably should
be using -pedantic.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2002-02-10 1:39 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-09 9:27 [PATCH] Fix PR gdb/290 kettenis
2002-02-09 11:19 ` Andrew Cagney
2002-02-09 11:37 ` Joe Buck
2002-02-09 11:51 ` Andrew Cagney
2002-02-09 12:18 ` Andreas Schwab
2002-02-09 17:39 ` Joe Buck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox