From: Kefu Chai Date: Thu, 7 Feb 2019 13:13:14 +0000 (+0800) Subject: msg/msg_types.h: do not cast `ceph_entity_name` to `entity_name_t` for printing X-Git-Tag: v13.2.7~10^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F31275%2Fhead;p=ceph.git msg/msg_types.h: do not cast `ceph_entity_name` to `entity_name_t` for printing in GCC-9, `-Waddress-of-packed-member` is enabled, so we have warnings like: src/msg/msg_types.h:142:41: warning: converting a packed 'const ceph_entity_name' pointer (alignment 1) to a 'const entity_name_t' pointer (alignment 8) may result in an unaligned pointer value [-Waddress-of-packed-member] 142 | return out << *(const entity_name_t*)&addr; | ^~~~ since the alignment of these two structures are different, we cannot cast a structure with the alignment of 1 to a structure with the alignment of 8. as the code generated by compiler accessing the members of alignment 8 won't work with the members of alignment 1, we need to create a temporary structure for printing it. Signed-off-by: Kefu Chai (cherry picked from commit f1bfe9dbad669faacfde4e74f38fe92253e5a91e) --- diff --git a/src/msg/msg_types.h b/src/msg/msg_types.h index 66ca945a56c4..84625aeff24c 100644 --- a/src/msg/msg_types.h +++ b/src/msg/msg_types.h @@ -137,7 +137,7 @@ inline std::ostream& operator<<(std::ostream& out, const entity_name_t& addr) { return out << addr.type_str() << '.' << addr.num(); } inline std::ostream& operator<<(std::ostream& out, const ceph_entity_name& addr) { - return out << *(const entity_name_t*)&addr; + return out << entity_name_t{addr.type, static_cast(addr.num)}; } namespace std {