Advertisements
I don’t understand why the following code gives the "type qualifiers ignored on cast result type" warning in GCC, can you please explain?
#include <stdint.h>
char f(const void* const a) noexcept {
return static_cast<char>(*static_cast<const char* const>(a));
}
https://godbolt.org/z/n8Ws9aTcq
>Solution :
A non-class non-array prvalue cannot be cv-qualified.
This means that your static_cast<const char* const>(a)
is exactly the same as static_cast<const char*>(a)
, the pointer itself isn’t const-qualified. It’s simply discarded, which is what the warning is telling you about (the second const
is what is being ignored)