Clang warnings in itemrepository.h: cast from 'char *' to ... increases required alignment
Milian Wolff
mail at milianw.de
Sat Aug 3 23:40:19 UTC 2013
On Sunday 04 August 2013 01:25:19 Milian Wolff wrote:
> Hey all,
>
> I'm nowadays building KDevelop with clang to great success. Highly annoying
> though are warnings like these which get emitted _everywhere_:
>
> /home/milian/projects/compiled/kde4/include/kdevplatform/language/duchain/re
> positories/itemrepository.h:178:25: warning: cast from 'char *' to 'unsigned
> short *' increases required alignment from 1 to 2 [-Wcast-align]
> m_objectMap = (short unsigned int*)current;
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> This comes with ca. 20 additional lines of context information for multiple
> locations in itemrepository.h. Since that is included in many files, we get
> tons of these warnings. If I make a compile error, I actually have to search
> very hard for the error messages now, since they get drowned in all these
> warnings. Bad, that makes me unproductive :(
>
> So, lets do the right thing and fix these issues, right?! But how?
> Especially an issue I see is that we get data from either QFile::map (i.e.
> uchar*) or just read it directly from QIODevice/QFile (i.e. char*).
>
> Afterwards we read all kinds of serialized data there (remember, the speed
> of our serialization is just because we do more or less 1to1 memory
> dumps!). So how can I ever "safely" read something like an int from a
> char*? It will always be a potential alignment increase, right? How can I
> shut this warning up?
Apparently with a fair dose of reinterpret_cast<>() instead of c-style casts.
Still, isn't the issue that clang warns us about here relevant? Sure, we don't
run on ARM hardware anyways, but besides that? Should one fix anything here?
Bye
--
Milian Wolff
mail at milianw.de
http://milianw.de
More information about the KDevelop-devel
mailing list