Discussion:
[KPhotoAlbum] Warnings
Tobias Leupold
2016-01-19 19:44:14 UTC
Permalink
Hi all again,

I also wanted to ask this: The KPA wiki says that the KPA build process is
"warning free zone". Actually, we currently have two warnings:


One appears during cmake (I don't know since when, it's new ...):

CMake Warning (dev) at /usr/lib64/automoc4/Automoc4Config.cmake:179
(get_directory_property):
Policy CMP0059 is not set: Do no treat DEFINITIONS as a built-in directory
property. Run "cmake --help-policy CMP0059" for policy details. Use the
cmake_policy command to set the policy and suppress this warning.
Call Stack (most recent call first):
/usr/lib64/automoc4/Automoc4Config.cmake:243 (_add_automoc4_target)
/usr/share/apps/cmake/modules/KDE4Macros.cmake:1003
(_automoc4_kde4_pre_target_handling)
CMakeLists.txt:451 (kde4_add_executable)
This warning is for project developers. Use -Wno-dev to suppress it.


The other one during building:

/home/tobias/tmp/1/kphotoalbum-4.7/RemoteControl/RemoteCommand.cpp: In
function 'QDataStream& operator>>(QDataStream&, RemoteControl::Category&)':
/home/tobias/tmp/1/kphotoalbum-4.7/RemoteControl/RemoteCommand.cpp:125:68:
warning: dereferencing type-punned pointer will break strict-aliasing rules [-
Wstrict-aliasing]
stream >> category.name >> category.enabled >> (int&) category.viewType;
^

I don't know how to fix neither the first, nor the second one. Does anybody?!
:-)

Tobias
Johannes Zarl-Zierl
2016-01-19 22:17:18 UTC
Permalink
Hi Tobias,
Post by Tobias Leupold
I also wanted to ask this: The KPA wiki says that the KPA build process is
CMake Warning (dev) at /usr/lib64/automoc4/Automoc4Config.cmake:179
Policy CMP0059 is not set: Do no treat DEFINITIONS as a built-in directory
property. Run "cmake --help-policy CMP0059" for policy details. Use the
cmake_policy command to set the policy and suppress this warning. Call
/usr/lib64/automoc4/Automoc4Config.cmake:243 (_add_automoc4_target)
/usr/share/apps/cmake/modules/KDE4Macros.cmake:1003
(_automoc4_kde4_pre_target_handling)
CMakeLists.txt:451 (kde4_add_executable)
This warning is for project developers. Use -Wno-dev to suppress it.
I don't see this warning on my own system. I think this is a bug within
KDE4Macros.cmake.
Post by Tobias Leupold
/home/tobias/tmp/1/kphotoalbum-4.7/RemoteControl/RemoteCommand.cpp: In
warning: dereferencing type-punned pointer will break strict-aliasing rules
[- Wstrict-aliasing]
stream >> category.name >> category.enabled >> (int&)
category.viewType; ^
I had hoped that somebody else would do it (and in this one case I think that
the warning will not lead to an actual bug). Your prodding, however has pushed
me over the edge to go and investigate it further...

What happens here?
Somewhere else, category.viewType (which is an enum) is written to a stream as
int. The code here is the reverser step, where the int is converted back into
an enum value.
The conversion back into an int is a potential problem, because the enum is of
different size than an int, and we tell the code to potentially write an int
value into a location that does not have space for it.

What can we do about it?
Let the stream write into a temporary int, and cast the temporary value to the
enum. This means that the compiler can at least make sure that the value that
is written into the enum "fits".

int tmp;
stream >> category.name >> category.enabled >> tmp;
category.viewType = static_cast<RemoteControl::CategoryViewType>(tmp);

I'm committing this fix in a minute or so...

Cheers,
Johannes

Loading...