Problem with GCC 4.9.0, Wextra, c++1y, and post-preprocessed linux header files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,

We've hit an issue in GCC 4.9.0 that affects applications that
preprocess their source before building it.  For example, using ccache
with its default settings causes the compiler to be invoked twice,
once to preprocess (and check the cache), and then if cache misses, to
build, but with the post-pre-processed file.

The issue we have is that the system macros htonl etc on linux are
defined to expand to:

(__extension__ ({ register unsigned int __v, __x = (_ip); if
(__builtin_constant_p (__x)) __v = ((((__x) & 0xff000000) >> 24) |
(((__x) & 0x00ff0000) >> 8) | (((__x) & 0x0000ff00) << 8) | (((__x) &
0x000000ff) << 24)); else __asm__ ("bswap %0" : "=r" (__v) : "0"
(__x)); __v; }))

When invoked via ccache -Wextra and -std=c++1y this line causes the error:
   error: address requested for ‘__x’, which is declared ‘register’
[-Werror=extra]

However, when invoked directly, this error is somehow suppressed.  Is
GCC aware of the fact this macro was defined in a system header and
thus suppresses the error?  And therefore if it's
previously-preprocessed, this tagging is lost?

Minimal reproduction case:

====
$ cat test.cc
#include <cstdint>
#include <netinet/in.h>

uint32_t test(uint32_t x) { return htonl(x); }
$ g++-4.9.0 -Wextra -O -std=c++1y -c test.cc  # compiles without error
$ g++-4.9.0 -Wextra -O -std=c++1y -c test.cc -E > test.preprocessed.cc
$ g++-4.9.0 -Wextra -O -std=c++1y -c test.preprocessed.cc
test.cc: In function ‘uint32_t test(uint32_t)’:
test.cc:4:134: warning: address requested for ‘__x’, which is declared
‘register’ [-Wextra]
 uint32_t test(uint32_t x) { return htonl(x); }
====

This only happens with std=c++1y, Wextra and -O (which macro-izes
htonl instead of making it an external function).  It does not happen
with std=c++11.

Does anyone have a suggestion as to how to work around this issue? It
seems we can't disable just the address-of-register warning, only
Wextra itself (which removes other warnings we'd like).

Thanks in advance, Matt

-- 
Matt





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux