在Windows上使用Boost-1.67.0和VS构建,我得到一个C4702"无法访问" boost::beast::http::detail::verb_to_string(verb v)
中的boost/beast/http/impl/verb.ipp
警告:
template<class = void>
inline string_view verb_to_string(verb v)
{
switch(v)
{
case verb::delete_: return "DELETE";
case verb::get: return "GET";
case verb::head: return "HEAD";
case verb::post: return "POST";
case verb::put: return "PUT";
case verb::connect: return "CONNECT";
o o o
case verb::unknown:
return "<unknown>";
}
BOOST_THROW_EXCEPTION(std::invalid_argument{"unknown verb"});
// Help some compilers which don't know the next line is
// unreachable, otherwise spurious warnings are generated.
return "<unknown>";
}
添加了最后一个(底部)return "<unknown>";
以安抚编译器,这些编译器不够聪明,不知道抛出的异常会阻止正常返回;但是,相同的代码行对于(更聪明的)Visual Studio来说是有问题的,它将语句标记为无法访问(C4702)。在我的例子中,我们将编译器警告转换为错误,因此它不仅仅是令人烦恼。
以下hack从@ DanielSeither对Disable single warning error的回答中获得了一些启发,似乎有效:
//
// Filename: boost_beast_http.hpp-no-c4702
//
// i.e. #include "boost_beast_http.hpp-no-c4702"
//
// Should appear before any other boost/beast header.
//
#if defined(OS_WIN32) || defined(OS_WIN64)
#ifndef BOOST_BEAST_HTTP_VERB_HPP
#define BOOST_BEAST_HTTP_IMPL_VERB_IPP
#include <boost/beast/http/verb.hpp>
#undef BOOST_BEAST_HTTP_IMPL_VERB_IPP
#pragma warning( push )
#pragma warning( disable : 4702 )
#include <boost/beast/http/impl/verb.ipp>
#pragma warning( pop )
#endif
#endif
#include <boost/beast/http.hpp>
但是,如果没有修补Microsoft VC ++构建的源代码,有人会建议更好的解决方法吗?