[vlc-devel] [PATCH] Add dummy return values to silence the?compiler warnings NO RETURN IN NON-VOID function. The compiler can't know?that this function can't reach the end (typically due to for ( ; ; ).?Arguably the compiler should see an assert(), but it keeps on warning?(openSUSE'sBuild System, and possibly others, raise this to an error due to?potentual undefined behaviour due to undefined random data being returned.
Laurent Aimar
fenrir at elivagar.org
Tue May 4 09:58:04 CEST 2010
Hi,
On Tue, May 04, 2010 at 09:23:53AM +0200, Rémi Denis-Courmont wrote:
>
> On Tue, 04 May 2010 01:31:33 +0200, Laurent Aimar <fenrir at elivagar.org>
> wrote:
> >> diff --git a/src/modules/cache.c b/src/modules/cache.c
> >> index 3f09ad8..045525a 100644
> >> --- a/src/modules/cache.c
> >> +++ b/src/modules/cache.c
> >> @@ -333,6 +333,7 @@ static int dummy_callback (vlc_object_t *obj, const
> > char *name,
> >> {
> >> (void) obj; (void)name; (void)oldval; (void)newval; (void)data;
> >> assert (0);
> >> + return 0; /* dead code, but the compiler can't know */
> >> }
> > For this one, I agree it might be better to add it as the compiler
> > can't know it, but I will let Rémi comments.
>
> Same problem as 'for(;;); return 0;' really.
>
> This code expands to something like:
> if (!0)
> {
> fputs ("Assertion `!0' failed!\n", stderr);
> abort (); /* no return function */
> }
> return 0;
When assert are activated yes, otherwise the function expand to
static int dummy_callback (vlc_object_t *obj, const ...)
{
}
and then it's normal for the compiler to warn about non returned value.
> Ideally, we would have a unreachable(); macro that would call assert(0),
> plus disable dead code and missing return value warnings, but I am not sure
> it is possible at all.
Well, with the gcc version I have under lenny, I don't have any warnings
about missing return value for the reported cases.
But I don't know if it is a regression of gcc or a too old gcc used for the
reported cases.
--
fenrir
More information about the vlc-devel
mailing list