Re: 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 Manuel - thanks for the reply.

On Thu, Apr 24, 2014 at 1:28 PM, Manuel López-Ibáñez
<lopezibanez@xxxxxxxxx> wrote:
> On 24 April 2014 18:44, Matt Godbolt <matt@xxxxxxxxxxx> 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





[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