This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/5455] New: Label before invoking pthread_cleanup_pop() produces syntax error.
- From: "prossi_bugz at pjrnet dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: 7 Dec 2007 03:12:50 -0000
- Subject: [Bug libc/5455] New: Label before invoking pthread_cleanup_pop() produces syntax error.
- Reply-to: sourceware-bugzilla at sourceware dot org
Newer versions of gcc (4.0.x and 4.1.x) with libc 2.5 and 2.4.x
will produce a "label at end of compound statement" syntax error
when compiling something like this:
#include <pthread.h>
. . .
pthread_cleanup_push( (void *)&cleaner, arg);
while (1)
{
< . . some code . . >
if (error) goto done;
< . . some more code . . >
}
done:
pthread_cleanup_pop(0);
While this may not really be a true "bug", the error that it reported
is very misleading in this situation and I thought it was worth
mentioning. The problem is that pthread_cleanup_push() and
pthread_cleanup_pop() are macros, and the pair make up a compound
statement, and now that gcc no longer allows a label like this at
the end of compound statement, you get the syntax error. The raw
source code *looks* just fine which makes it quite misleading until
you figure out all of the pieces and exactly what is going on.
The solution of course is to add a semicolon after "done:"
Seems like in this case, either the label restriction could be better
documented (in pthread.h ?) or the pthread_cleanup_pop(0) macro could
be modified to account for the possibility of a label before it, by
beginning the macro definition with a semicolon (null statement). It's
just one of those things that can drive you crazy tracking down but
is so simple once you figure it all out.
I felt this was worth reporting but was not sure if this was the best way.
This problem was observed on various systems with gcc 4.1.0 and 4.1.1
and with various libc 2.4 and 2.5 A minimal test case without
using pthread.h but duplicating the code structure of the macro calls,
also fails on these same platforms, however will compile on older
gcc 2.7 and 2.92 gcc systems which don't have the label restriction.
Also, the essence of the code fragment above is from some actual code
(that I did not write) that is being ported from AIX/xlc to Linux/gcc.
Unfortunately we are not permitted to make any changes that are not
absolutely necessary to complete the port to reduce the amount of
regression testing .. so unfortunately the 'goto' must stay (for now).
I would have never used a 'goto' for something like this, or any goto,
in the first place. I often tell people " I haven't used a 'goto' in
so long now, that I forgot how to spell it " :-)
--
Summary: Label before invoking pthread_cleanup_pop() produces
syntax error.
Product: glibc
Version: unspecified
Status: NEW
Severity: minor
Priority: P3
Component: libc
AssignedTo: drepper at redhat dot com
ReportedBy: prossi_bugz at pjrnet dot com
CC: glibc-bugs at sources dot redhat dot com
http://sourceware.org/bugzilla/show_bug.cgi?id=5455
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.