[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.

Rémi Denis-Courmont remi at remlab.net
Tue May 4 09:23:53 CEST 2010

On Tue, 04 May 2010 01:31:33 +0200, Laurent Aimar <fenrir at elivagar.org>
>> 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;

which the compiler may as optimize:

    fputs ("Assertion `!0' failed!\n", stderr);
    abort (); /* no return function */
    return 0; /* <-- dead code! */

Note that abort() is declared as a no-return function in glibc <stdlib.h>.
That being said, the compiler could also warn that assert(0) is dead

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.

Rémi Denis-Courmont

More information about the vlc-devel mailing list