This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: C++ PATCH to warn about inlines which fail to return a value
- From: Michael Elizabeth Chastain <mec at shout dot net>
- To: jason at redhat dot com
- Cc: fjh at cs dot mu dot oz dot au, gcc-patches at gcc dot gnu dot org, jimb at redhat dot com
- Date: Sun, 10 Feb 2002 23:31:57 -0600
- Subject: Re: C++ PATCH to warn about inlines which fail to return a value
The gdb test suite has two function definitions which trigger this new warning.
Instance #1:
/* from gdb/testsuite/gdb.base/funcargs.c */
/* note: PROTOTYPES is not defined */
...
/* On various machines (pa, 29k, and rs/6000, at least), a function which
calls alloca may do things differently with respect to frames. So give
it a try. */
#ifdef PROTOTYPES
void localvars_after_alloca (char c, short s, int i, long l)
#else
int
localvars_after_alloca (c, s, i, l)
char c;
short s;
int i;
long l;
#endif
{
#ifdef HAVE_STACK_ALLOCA
/* No need to use the alloca.c alloca-on-top-of-malloc; it doesn't
test what we are looking for, so if we don't have an alloca which
allocates on the stack, just don't bother to call alloca at all. */
char *z = alloca (s + 50);
#endif
c = 'a';
s = 5;
i = 6;
l = 7;
}
Instance #2:
/* from gdb/testsuite/gdb.threads/linux-dp.exp */
...
void *
philosopher (void *data)
{
int n = * (int *) data;
print_philosopher (n, '_', '_');
#if 1
if (n == num_philosophers - 1)
for (;;)
{
/* The last philosopher is different. He goes for his right
fork first, so there is no cycle in the mutex graph. */
/* Grab the right fork. */
pthread_mutex_lock (&fork_mutex[(n + 1) % num_philosophers]);
print_philosopher (n, '_', '!');
random_delay ();
/* Then grab the left fork. */
pthread_mutex_lock (&fork_mutex[n]);
print_philosopher (n, '!', '!');
random_delay ();
print_philosopher (n, '_', '_');
pthread_mutex_unlock (&fork_mutex[n]);
pthread_mutex_unlock (&fork_mutex[(n + 1) % num_philosophers]);
random_delay ();
}
else
#endif
for (;;)
{
/* Grab the left fork. */
pthread_mutex_lock (&fork_mutex[n]);
print_philosopher (n, '!', '_');
random_delay ();
/* Then grab the right fork. */
pthread_mutex_lock (&fork_mutex[(n + 1) % num_philosophers]);
print_philosopher (n, '!', '!');
random_delay ();
print_philosopher (n, '_', '_');
pthread_mutex_unlock (&fork_mutex[n]);
pthread_mutex_unlock (&fork_mutex[(n + 1) % num_philosophers]);
random_delay ();
}
}
Instance #1 is bad, broken code and I have already fixed the return type of
the function to 'void'. I like the warning in #1.
Instance #2 is more problematic. The 'philosopher' function is an argument to
pthread_create, so it must return a void * per the interface. And it's very
natural for an argument to 'pthread_create" to have a "for(;;)" loop with no
return statement.
So I believe the new warning is going to give frequent false positives in the
field. My opinion as a user of gcc is that such a warning should not be
enabled by default or by -Wall either; that it should have its own flag.
If gcc keeps the warning as is I'll just make the trival adjustment,
no problem. I do whatever the voice in my mailbox tell me. :) I just
want to supply some field data in support of Fergus's point.
Michael Elizabeth Chastain
<mailto:mec@shout.net>
"love without fear"