在C++应用程序中使用boost 1.4.2 asio并得到linux编译器警告我不喜欢。boost asio ssl流套接字编译问题
还在吗?
我正在处理的应用程序需要一个可能是ssl套接字或常规tcp套接字的“套接字”,因此我们在模板“套接字”类后面隐藏了具体的 ,该套接字可以使用ssl套接字类或 tcp套接字类作为模板参数 - 下面是ssl类代码。
该应用程序无需打开任何优化即可正常运行;问题是当我在linux g ++ 4.4.1 下编译并打开-02或更高优化时,-fstrict-aliasing标志打开。 编译导致沿线的严格别名警告: “警告:提领型punned指针将打破严格走样规则” 无处不在我取_psock(如_psock->握手)
我想知道为什么这个警告被发出,并且它表明一个设计问题...
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 {
// the one and only ssl context
// hardcoded for test, but get these values from 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, then shutdown socket, then 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;
};
所有-02痛苦编译输出开启,这会导致-fstrict走样
../。 ./../../third-party/boost/1.42.0/boost/function/function_base.hpp :321:警告:取消引用类型指针会打破严格别名规则 ../../../../third-party/boost/1.42.0/boost/function/function_base.hpp:325:warning :解引用类型指针会破坏严格别名规则 ../../../../third-party/boost/1.42.0/boost/function/function_base.hpp:在静态成员函数'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:从'static void boost :: detail :: function :: functor_manager :: manager(const boost :: detail :: function :: function_buffer 01 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:从'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:从'static void boost :: detail :: function :: functor_manager :: manage(const boost :: detail :: function: :本功能ion_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:从'void boost :: function0 :: assign_to'实例化(Functor)[with Functor = boost :: _ bi :: bind_t> >>,boost :: _ bi :: list1 >> * >> >>,R = int]' ../../../../第三方/ boost/1.42.0/boost/function/function_template.hpp:722:从'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_template。hpp:1064:从'boost :: function :: function(Functor,typename boost :: enable_if_c :: type)[使用Functor = boost :: _ bi :: bind_t>>>,boost :: _ bi :: list1>> *>>>,R = int]' ../../../../third-party/boost/1.42.0/boost/function/function_template.hpp:1105:从'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:从'boost :: asio :: ssl ::详细信息:: openssl_operation :: openssl_operation(boost :: asio :: ssl :: detail :: ssl_primitive_func,Stream &,boost :: asio :: ssl :: detail :: net_buffer &,SSL *,BIO *)[Stream = boost :: asio :: basic_stream_socket>]' ../../../../third-party/boost/1.42。 0/boost/asio/ssl/detail/openssl_stream_service.hpp:510:从'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:从'boost :: system :: error_code boost :: instantiated':: 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:从'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:从这里