[Bug c++/89722] [8/9 regression] strange warning: type qualifiers ignored on cast result type [-Wignored-qualifiers]
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Mar 15 00:01:00 GMT 2019
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89722
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Xavier from comment #0)
> This does not seem to occur with gcc, nor with g++ <= 7.
I implemented the warning for GCC 8.
> I could not find a workaround.
Stop using macros?
template<typename T>
constexpr size_t bitsizeof()
{ return sizeof(T) * CHAR_BIT; }
template<typename T>
T bitmask_nth(T n)
{ return (T)1 << (n & (bitsizeof<T>() - 1)); }
template<typename T>
T test_bit(T* bits, unsigned n)
{ return bits[n / bitsizeof<T>()] & bitmask_nth((T)n); }
> Clearly I cannot remove the cast : for shifting 32 bits or more, we need to
> be on a int64.
You can either use std::remove_const_t<typeof(*bits)> to get the unqualified
version of the type, or just use decltype as Andrew suggested.
The warning seems correct, typeof(*d->tab) is const int64_t, and casting (const
int64_t)1 is defined by the language to be the same as (int64_t)1 so the const
is ignored.
More information about the Gcc-bugs
mailing list