c++ - boost asio ssl stream socket compilation issue -
using boost 1.4.2 asio in c++ app , getting linux compiler warnings don't grok.
still here?
app i'm working on needs "socket" might ssl socket or regular tcp socket hide specifics behind template "socket" class takes either ssl socket class or tcp socket class template parameter - below ssl class code.
app runs without optimization turned on; issue when compile under linux g++ 4.4.1 , turn on optimization @ -02 or higher, -fstrict-aliasing flag turned on. compiling results in strict aliasing warnings along lines of: "warning: dereferencing type-punned pointer break strict-aliasing rules" everywhere dereference _psock (eg _psock->handshake)
i'd know why warning being issued, , indicate design problem...
class socket_ssl_cli { public: typedef ba::ssl::stream<ba::ip::tcp::socket> socket_type; socket_ssl_cli(ba::io_service& io_svc, socketconfig & sockcfg) : _io_svc(io_svc) , _ctxt(_io_svc, ba::ssl::context::tlsv1) , _psock(0) { try { // 1 , ssl context // hardcoded test, these values config _ctxt.set_options(ba::ssl::context::default_workarounds | ba::ssl::context::verify_none); _psock = new socket_type(_io_svc, _ctxt); } catch (bs::system_error & x) { throw std::runtime_error(x.code().message()); } } ~socket_ssl_cli() { if (_psock) { bs::error_code ec; close_socket(ec); delete _psock; } } socket_type & raw_socket() { return *_psock; } void setup(bs::error_code & ec) { _psock->handshake(ba::ssl::stream_base::client, ec); } void close_socket(bs::error_code & ec) { // shut down ssl, shutdown socket, close socket _psock->shutdown(ec); _psock->lowest_layer().shutdown(ba::socket_base::shutdown_both, ec); _psock->lowest_layer().close(ec); } private: ba::io_service & _io_svc; ba::ssl::context _ctxt; socket_type * _psock; };
all painful compile output -02 turned on, results in -fstrict-aliasing
../../../../third-party/boost/1.42.0/boost/function/function_base.hpp:321: warning: dereferencing type-punned pointer break strict-aliasing rules ../../../../third-party/boost/1.42.0/boost/function/function_base.hpp:325: warning: dereferencing type-punned pointer break strict-aliasing rules ../../../../third-party/boost/1.42.0/boost/function/function_base.hpp: in static member function ‘static void boost::detail::function::functor_manager_common::manage_small(const boost::detail::function::function_buffer&, boost::detail::function::function_buffer&, boost::detail::function::functor_manager_operation_type) [with functor = boost::_bi::bind_t > > >, boost::_bi::list1 > >*> > >]’: ../../../../third-party/boost/1.42.0/boost/function/function_base.hpp:360: instantiated ‘static void boost::detail::function::functor_manager::manager(const boost::detail::function::function_buffer&, boost::detail::function::function_buffer&, boost::detail::function::functor_manager_operation_type, mpl_::true_) [with functor = boost::_bi::bind_t > > >, boost::_bi::list1 > >*> > >]’ ../../../../third-party/boost/1.42.0/boost/function/function_base.hpp:406: instantiated ‘static void boost::detail::function::functor_manager::manager(const boost::detail::function::function_buffer&, boost::detail::function::function_buffer&, boost::detail::function::functor_manager_operation_type, boost::detail::function::function_obj_tag) [with functor = boost::_bi::bind_t > > >, boost::_bi::list1 > >*> > >]’ ../../../../third-party/boost/1.42.0/boost/function/function_base.hpp:434: instantiated ‘static void boost::detail::function::functor_manager::manage(const boost::detail::function::function_buffer&, boost::detail::function::function_buffer&, boost::detail::function::functor_manager_operation_type) [with functor = boost::_bi::bind_t > > >, boost::_bi::list1 > >*> > >]’ ../../../../third-party/boost/1.42.0/boost/function/function_template.hpp:913: instantiated ‘void boost::function0::assign_to(functor) [with functor = boost::_bi::bind_t > > >, boost::_bi::list1 > >*> > >, r = int]’ ../../../../third-party/boost/1.42.0/boost/function/function_template.hpp:722: instantiated ‘boost::function0::function0(functor, typename boost::enable_if_c::type) [with functor = boost::_bi::bind_t > > >, boost::_bi::list1 > >*> > >, r = int]’ ../../../../third-party/boost/1.42.0/boost/function/function_template.hpp:1064: instantiated ‘boost::function::function(functor, typename boost::enable_if_c::type) [with functor = boost::_bi::bind_t > > >, boost::_bi::list1 > >*> > >, r = int]’ ../../../../third-party/boost/1.42.0/boost/function/function_template.hpp:1105: instantiated ‘typename boost::enable_if_c&>::type boost::function::operator=(functor) [with functor = boost::_bi::bind_t > > >, boost::_bi::list1 > >*> > >, r = int]’ ../../../../third-party/boost/1.42.0/boost/asio/ssl/detail/openssl_operation.hpp:134: instantiated ‘boost::asio::ssl::detail::openssl_operation::openssl_operation(boost::asio::ssl::detail::ssl_primitive_func, stream&, boost::asio::ssl::detail::net_buffer&, ssl*, bio*) [with stream = boost::asio::basic_stream_socket >]’ ../../../../third-party/boost/1.42.0/boost/asio/ssl/detail/openssl_stream_service.hpp:510: instantiated ‘boost::system::error_code boost::asio::ssl::detail::openssl_stream_service::handshake(boost::asio::ssl::detail::openssl_stream_service::impl_struct*&, stream&, boost::asio::ssl::stream_base::handshake_type, boost::system::error_code&) [with stream = boost::asio::basic_stream_socket >]’ ../../../../third-party/boost/1.42.0/boost/asio/ssl/stream_service.hpp:100: instantiated ‘boost::system::error_code boost::asio::ssl::stream_service::handshake(boost::asio::ssl::detail::openssl_stream_service::impl_struct*&, stream&, boost::asio::ssl::stream_base::handshake_type, boost::system::error_code&) [with stream = boost::asio::basic_stream_socket >]’ ../../../../third-party/boost/1.42.0/boost/asio/ssl/stream.hpp:207: instantiated ‘boost::system::error_code boost::asio::ssl::stream::handshake(boost::asio::ssl::stream_base::handshake_type, boost::system::error_code&) [with stream = boost::asio::basic_stream_socket >, service = boost::asio::ssl::stream_service]’ ../sockets/socket_ssl_cli.h:45: instantiated here
read boost wiki explaining compiler warning guidelines
https://svn.boost.org/trac/boost/wiki/guidelines/warningsguidelines
they have whole section dedicated -fstrict-aliasing
-fstrict-aliasing - turned on -o2, -o3 , -os. tells compiler it's ok class of optimization based on type of expressions. in particular you're promising using flag object of 1 type won't reside @ same address object of incompatible type. -fno-strict-aliasing - turns off optimization. if changes behavior of code, have problem in code.
this trying let know asking compiler undefined behavior , may not think do. optimization level increases, liklihood won't increase. show simple example later surprisingly generates wrong result when optimization @ level turned on. ignore warning @ own peril. unlikely care undefined behavior results.
Comments
Post a Comment