Dav*_*ter 5 c++ clang unary-function c++11
我通过 vcpkg 安装了 boost-program-options 版本 1.78。当我编译时clang++,-std=c++20出现以下错误。当我用 编译时不会发生这种情况g++。据此,从 C++11 开始,这已被弃用。 std::unary_function
In file included from /home/david/C/vcpkg/installed/x64-linux/include/boost/program_options/variables_map.hpp:12:
In file included from /home/david/C/vcpkg/installed/x64-linux/include/boost/any.hpp:20:
In file included from /home/david/C/vcpkg/installed/x64-linux/include/boost/type_index.hpp:29:
In file included from /home/david/C/vcpkg/installed/x64-linux/include/boost/type_index/stl_type_index.hpp:47:
/home/david/C/vcpkg/installed/x64-linux/include/boost/container_hash/hash.hpp:132:33: warning: 'unary_function<const std::error_category *, unsigned long>' is deprecated [-Wdeprecated-declarations]
struct hash_base : std::unary_function<T, std::size_t> {};
^
/home/david/C/vcpkg/installed/x64-linux/include/boost/container_hash/hash.hpp:692:18: note: in instantiation of template class 'boost::hash_detail::hash_base<const std::error_category *>' requested here
: public boost::hash_detail::hash_base<T*>
^
/home/david/C/vcpkg/installed/x64-linux/include/boost/container_hash/hash.hpp:420:24: note: in instantiation of template class 'boost::hash<const std::error_category *>' requested here
boost::hash<T> hasher;
^
/home/david/C/vcpkg/installed/x64-linux/include/boost/container_hash/hash.hpp:551:9: note: in instantiation of function template specialization 'boost::hash_combine<const std::error_category *>' requested here
hash_combine(seed, &v.category());
^
/bin/../lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/bits/stl_function.h:124:7: note: 'unary_function<const std::error_category *, unsigned long>' has been explicitly marked deprecated here
} _GLIBCXX11_DEPRECATED;
^
/bin/../lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/x86_64-redhat-linux/bits/c++config.h:2340:32: note: expanded from macro '_GLIBCXX11_DEPRECATED'
# define _GLIBCXX11_DEPRECATED _GLIBCXX_DEPRECATED
^
/bin/../lib/gcc/x86_64-redhat-linux/12/../../../../include/c++/12/x86_64-redhat-linux/bits/c++config.h:2331:46: note: expanded from macro '_GLIBCXX_DEPRECATED'
# define _GLIBCXX_DEPRECATED __attribute__ ((__deprecated__))
Run Code Online (Sandbox Code Playgroud)
为什么 boost 使用标准中已弃用的部分?忽略这些警告并压制有什么问题吗-Wno-deprecated-declarations?
自 MSVC 的 Boost 1.64 ( commit ) 和其他编译器 ( commit ) 的 Boost 1.73 起,已替换std::unary_function了不再支持它的编译器/标准库。
std::unary_function但只要没有检测到已删除,它就会继续默认使用。
自 Boost 1.80 起,std::unary_function在使用 C++11 或更高版本与 libstdc++(commit、issue)时,将禁用 Boost 以消除弃用警告,并且已为 libc++(commit、issue)合并了类似的补丁。后者似乎不包含在 1.80 版本中,但包含在 1.81 中。
因此,您要么等待/升级到最新版本的 Boost,手动添加补丁,要么将标头配置为系统标头,以便通常抑制它们的警告。(我不确定这在您的设置中是否完全可能。)或者使用您显示的标志禁用弃用警告,但这似乎很严厉。
在 C++17 模式或更高版本(其中该函数已完全删除)下进行编译可能也会有所帮助(尚未测试)。
在包含任何 boost 标头之前简单地定义宏BOOST_NO_CXX98_FUNCTION_BASE也可能有所帮助,但我无法判断它是否是供用户这样做的,或者是否可能会破坏其他 boost 内容。据我所知,它也可能默默地破坏 ABI。