From ad9871a5d1119593068f7e3a01d4249b4dff982a Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 23 Jan 2018 11:06:22 +0100 Subject: Introduce SbxValues::clear MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ...to avoid upcoming GCC 8 -Werror=class-memaccess ("clearing an object of non- trivial type ‘struct SbxValues’") Change-Id: Icf610e692b81030bfd6f2f940c43ee8bf6f1d4e0 Reviewed-on: https://gerrit.libreoffice.org/48389 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- include/basic/sbxvar.hxx | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'include/basic') diff --git a/include/basic/sbxvar.hxx b/include/basic/sbxvar.hxx index b189d4e32c26..1908ce83b73e 100644 --- a/include/basic/sbxvar.hxx +++ b/include/basic/sbxvar.hxx @@ -24,6 +24,9 @@ #include #include #include + +#include +#include #include @@ -71,6 +74,15 @@ struct SbxValues SbxValues(): pData( nullptr ), eType(SbxEMPTY) {} SbxValues( SbxDataType e ): eType(e) {} SbxValues( double _nDouble ): nDouble( _nDouble ), eType(SbxDOUBLE) {} + + void clear(SbxDataType type) { + // A hacky way of zeroing the union value corresponding to the given type (even though the + // relevant zero value need not be represented by all-zero bits, in general) without evoking + // GCC 8 -Wclass-memaccess, and without having to turn the anonymous union into a non- + // anonymous one: + std::memset(static_cast(this), 0, offsetof(SbxValues, eType)); + eType = type; + } }; class BASIC_DLLPUBLIC SbxValue : public SbxBase -- cgit