[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi] [PATCH] Fix build with g++5
From: |
Vadim Zeitlin |
Subject: |
[lmi] [PATCH] Fix build with g++5 |
Date: |
Wed, 16 Sep 2015 00:50:54 +0200 |
Hello,
I'm not sure why I didn't see this warning before, even with g++ 4.9, but
with 5.2.1 I now get the following warnings when building lmi:
---------------------------------- >8 --------------------------------------
% make
alert_cli.cpp:41:10: error: '{anonymous}::ensure_setup' defined but not used
[-Werror=unused-variable]
bool ensure_setup = set_alert_functions
^
...
md5.cpp: In function 'void* md5_finish_ctx(md5_ctx*, void*)':
md5.cpp:164:43: error: dereferencing type-punned pointer will break
strict-aliasing rules [-Werror=strict-aliasing]
*(md5_uint32 *) &ctx->buffer[bytes + pad] = SWAP (ctx->total[0] << 3);
^
md5.cpp:165:47: error: dereferencing type-punned pointer will break
strict-aliasing rules [-Werror=strict-aliasing]
*(md5_uint32 *) &ctx->buffer[bytes + pad + 4] = SWAP ((ctx->total[1] << 3) |
^
...
CXX liblmi_la-actuarial_table.lo
actuarial_table.cpp: In member function 'void
soa_actuarial_table::find_table()':
actuarial_table.cpp:577:60: error: dereferencing type-punned pointer will break
strict-aliasing rules [-Werror=strict-aliasing]
*reinterpret_cast<boost::int32_t*>(index_record)
actuarial_table.cpp: In member function 'void
soa_actuarial_table::read_values(std::istream&, int)':
actuarial_table.cpp:813:48: error: dereferencing type-punned pointer will break
strict-aliasing rules [-Werror=strict-aliasing]
data_[j] = *reinterpret_cast<double*>(z);
^
actuarial_table.cpp: In instantiation of 'T
{anonymous}::read_datum(std::istream&, T&, int16_t) [with T = short int;
std::istream = std::basic_istream<char>; int16_t = short int]':
actuarial_table.cpp:663:65: required from here
actuarial_table.cpp:87:11: error: dereferencing type-punned pointer will break
strict-aliasing rules [-Werror=strict-aliasing]
t = *reinterpret_cast<T*>(z);
^
actuarial_table.cpp: In instantiation of 'T
{anonymous}::read_datum(std::istream&, T&, int16_t) [with T = short unsigned
int; std::istream = std::basic_istream<char>; int16_t = short int]':
actuarial_table.cpp:666:68: required from here
actuarial_table.cpp:87:11: error: dereferencing type-punned pointer will break
strict-aliasing rules [-Werror=strict-aliasing]
actuarial_table.cpp: In instantiation of 'T
{anonymous}::read_datum(std::istream&, T&, int16_t) [with T = int; std::istream
= std::basic_istream<char>; int16_t = short int]':
actuarial_table.cpp:673:55: required from here
actuarial_table.cpp:87:11: error: dereferencing type-punned pointer will break
strict-aliasing rules [-Werror=strict-aliasing]
cc1plus: all warnings being treated as errors
---------------------------------- >8 --------------------------------------
The first attached patch fixes the first warning by adding "volatile"
keyword to alert_*.cpp files, just as it was already done elsewhere.
The second patch fixes the remaining ones by modifying the code to
explicitly use std::memcpy(). Alternatively, the usual union trick could be
used, but I thought you might frown on using it and memcpy() is arguably
more clear. But please let me know if you disagree.
After fixing the above warnings I got the following link error:
---------------------------------- >8 --------------------------------------
CXXLD lmi_wx
./.libs/liblmi.so: undefined reference to
`trammel_base<calendar_date>::minimum_minimorum() const'
./.libs/liblmi.so: undefined reference to
`trammel_base<int>::maximum_maximorum() const'
collect2: error: ld returned 1 exit status
Makefile:3068: recipe for target 'lmi_wx' failed
make: *** [lmi_wx] Error 1
---------------------------------- >8 --------------------------------------
AFAICS this is due to the fact that g++5 just inlines these methods
directly when instantiating tn_range<> but doesn't generate them at all. To
be honest, I'm not 100% sure if it's allowed to do this, but I think it is
and, in any case, it definitely does. So I also had to add explicit
instantiations of trammel_base<> to fix this in the third patch.
After applying them I can build lmi with g++ 5.2 and I could verify that
PDF group premium quotes generation worked correctly with the binary built
with it. I've also checked that the tests (including authenticity and
acturial_table ones) still pass with 3.4.5 after these changes.
Thanks in advance for applying them,
VZ
0001-Make-bool-variable-volatile-to-avoid-unused-variable.patch
Description: Text document
0002-Avoid-g-5-warnings-about-breaking-strict-aliasing.patch
Description: Text document
0003-Explicitly-instantiate-trammel_base-for-the-types-us.patch
Description: Text document
- [lmi] [PATCH] Fix build with g++5,
Vadim Zeitlin <=
- Re: [lmi] [PATCH] Fix build with g++5, Greg Chicares, 2015/09/17
- Re: [lmi] [PATCH] Fix build with g++5, Vadim Zeitlin, 2015/09/17
- Re: [lmi] [PATCH] Fix build with g++5, Greg Chicares, 2015/09/18
- Re: [lmi] Working with and around strict aliasing (was: Fix build with g++5), Vadim Zeitlin, 2015/09/18
- Re: [lmi] Working with and around strict aliasing, Greg Chicares, 2015/09/19
- Re: [lmi] Working with and around strict aliasing, Vadim Zeitlin, 2015/09/19
- Re: [lmi] Working with and around strict aliasing, Greg Chicares, 2015/09/20
- Re: [lmi] Working with and around strict aliasing, Vadim Zeitlin, 2015/09/20