Using g++ version 4.7.2, if I try compiling the following
#include <boost/date_time/local_time/local_time.hpp>
class Bar
{
public:
Bar() { tz_db_.load_from_file("/home/date_time_zonespec.csv"); }
private:
boost::local_time::tz_database tz_db_;
};
int main()
{
return 0;
}
with -std=c++0x I get the following error.
In file included from /usr/local/include/boost/date_time/local_time/local_time_types.hpp:18:0,
from /usr/local/include/boost/date_time/local_time/local_time.hpp:13,
from test.h:4,
from test.cpp:1: /usr/local/include/boost/date_time/local_time/custom_time_zone.hpp: In instantiation of ‘bool boost::local_time::custom_time_zone_base<CharT>::has_dst() const [with CharT = char]’: test.cpp:11:1: required from here /usr/local/include/boost/date_time/local_time/custom_time_zone.hpp:67:30: error: cannot convert ‘const boost::shared_ptr<boost::date_time::dst_day_calc_rule<boost::gregorian::date>
>’ to ‘bool’ in return
If I leave off the c++0x option, everything is fine. Can anybody tell me what's going on here?
When you build for C++11, boost::shared_ptr::operator bool()
is declared explicit
. This is generally a good thing to do, but unfortunately it breaks code that relies on implicit conversions, such as this function (which is the cause of your error):
virtual bool has_dst() const
{
return (dst_calc_rules_); //if calc_rule is set the tz has dst
}
where dst_calc_rules_
is a shared_ptr
.
Until someone at Boost gets round to fixing it, there are two things you could do:
return bool(dst_calc_rules_);
BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
to allow implicit conversions.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With