Bug 22856
| Summary: | glibc-2.2 code for htonl/etc won't compile with -O outside of a function body | ||
|---|---|---|---|
| Product: | [Retired] Red Hat Linux | Reporter: | j. alan eldridge <alane> |
| Component: | gcc | Assignee: | Jakub Jelinek <jakub> |
| Status: | CLOSED UPSTREAM | QA Contact: | David Lawrence <dkl> |
| Severity: | medium | Docs Contact: | |
| Priority: | medium | ||
| Version: | 7.0 | CC: | dr |
| Target Milestone: | --- | ||
| Target Release: | --- | ||
| Hardware: | i386 | ||
| OS: | Linux | ||
| Whiteboard: | |||
| Fixed In Version: | Doc Type: | Bug Fix | |
| Doc Text: | Story Points: | --- | |
| Clone Of: | Environment: | ||
| Last Closed: | 2004-10-05 22:54:07 UTC | Type: | --- |
| Regression: | --- | Mount Type: | --- |
| Documentation: | --- | CRM: | |
| Verified Versions: | Category: | --- | |
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |
| Cloudforms Team: | --- | Target Upstream Version: | |
| Embargoed: | |||
I see, but I think also older g++ (e.g. egcs 1.1.2 or gcc 2.95.2) did this and likewise older glibc (like 2.1.x). I see possible 4 solutions for this, am just mailing libc-hackers to discuss which way to go. G++ will accept this for gcc 4.0, but no prior versions. I suspect this largely due to the re-implementation of statement expressions for tree-ssa. Pushed upstream as a feature request to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17854 |
ok, this is kind of messy. first, we have /usr/include/netinet/in.h, which does: #ifdef __OPTIMIZE__ [ ... ] # if __BYTE_ORDER == __LITTLE_ENDIAN # define ntohl(x) __bswap_32 (x) # define ntohs(x) __bswap_16 (x) # define htonl(x) __bswap_32 (x) # define htons(x) __bswap_16 (x) # endif [ ... ] #endif then, in /usr/include/bits/byteswap.h, we get this: # define __bswap_32(x) \ (__extension__ \ ({ register unsigned int __v; \ if (__builtin_constant_p (x)) \ __v = __bswap_constant_32 (x); \ else \ __asm__ __volatile__ ("bswap %0" \ : "=r" (__v) \ : "0" ((unsigned int) (x))); \ __v; })) that's the background. take a small piece of c++ code that assigns a global scope variable using htonl() and "houston, we have a problem." [alane@wozzle /tmp]$ cat t.cc #include <netinet/in.h> uint32_t noaddr = htonl(INADDR_NONE); [alane@wozzle /tmp]$ g++ -c t.cc [alane@wozzle /tmp]$ g++ -O -c t.cc t.cc:3: braced-group within expression allowed only inside a function t.cc:3: ISO C++ forbids declaration of `__v' with no type t.cc:3: parse error before `}' [alane@wozzle /tmp]$ yes, i know this is *really* obscure. and it could just as well be taken as a bug in glibc. feel free to recategorize as such if that is warranted. problem is, it's just *so* weird, and the error message from compiling a perfectly reasonable piece of code is totally martian. i don't know what right fix is. i just put parens around the htonl call so it wouldn't macro expand. fsck. [sigh]