This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Problem with GCC 4.9.0, Wextra, c++1y, and post-preprocessed linux header files
- From: Matt Godbolt <matt at godbolt dot org>
- To: Manuel LÃpez-IbÃÃez <lopezibanez at gmail dot com>
- Cc: "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>, Nevin Liber <nliber at gmail dot com>
- Date: Thu, 24 Apr 2014 13:42:57 -0500
- Subject: Re: Problem with GCC 4.9.0, Wextra, c++1y, and post-preprocessed linux header files
- Authentication-results: sourceware.org; auth=none
- References: <CAFWXXN0y=qEV7pvQ+AfUzWaD-kGcSQZt1_WQqT+2+20YhpifDQ at mail dot gmail dot com> <CAESRpQD8cp_iw+8pD+BeDzmwLoah3Bt8Yvf7LnKMhFM7AXA3Pg at mail dot gmail dot com>
Hi Manuel - thanks for the reply.
On Thu, Apr 24, 2014 at 1:28 PM, Manuel LÃpez-IbÃÃez
<lopezibanez@gmail.com> wrote:
> On 24 April 2014 18:44, Matt Godbolt <matt@godbolt.org> wrote:
>>
>> (__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]
>
> Is this the actual output of GCC? GCC 4.9.0 should print column
> numbers and a caret pointing to the exact location in the macro
> expansion.
The caret was on the next line (that I didn't paste) - it is
approximately 130 characters off (beyond the end of the line) -
apologies I hadn't spotted the caret:
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); }
^
> From the piece that you quote, the warning seems just bogus, so I
> think you should open a PR (http://gcc.gnu.org/bugs/) independently of
> the preprocessed vs. non-preprocessed issue.
I will prepare a minimal example of this: I think it's relating to the
asm block, but will confirm and open a PR. Thanks.
>> 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?
>
> Maybe. Could you try
>
>> $ g++-4.9.0 -Wextra -O -std=c++1y -c test.cc # compiles without error
>
> this -Wsystem-headers?
I just tried this and -Wsystem-headers still exhibits the issue.
> Also, could you try building a testcase that doesn't use headers but
> it is not preprocessed?
I will do so and follow up here when I have a minimal example.
>> $ 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.
>
> Do std=c++11 vs std=c++1y change anything in the preprocessed file? If
> not, the only way to understand what is going on is to put a break
> point at the warning point and figure out why it is (wrongly) warning.
There are some small differences in the file, mainly due to different
headers being pulled in.
>
>> 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).
>
> As workarounds, you could try #pragma GCC diagnostics ignored "Wextra"
> around that code. Or you could submit a patch to add an option
> -Waddress-of-register to control this warning.
The pragma approach is tricky as references to htonl and htons are, as
you might imagine, scattered around the codebase. But thanks for the
pointers! And yes, a -Waddress-of-register patch would be a great
idea too; I'll look into that.
I will follow up with a minimal example (and a link to bugzilla) as
soon as I have found one.
Regards, Matt
--
Matt