c++ boost program-options使用过时的功能

a0zr77ik  于 11个月前  发布在  其他
关注(0)|答案(1)|浏览(94)

我通过vcpkg安装了boost-program-options 1.78版本。当我用clang++-std=c++20编译时,我得到以下错误。当我用g++编译时,不会发生这种情况。根据此thisstd::unary_function自C++11起被弃用。

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__))

字符串
为什么boost使用标准中不推荐的部分?忽略这些警告并使用-Wno-deprecated-declarations进行抑制有什么错吗?

7y4bm7vi

7y4bm7vi1#

对于不再支持std::unary_function的编译器/标准库,从MSVC的Boost 1.64(commit)和其他编译器的Boost 1.73(commit)起,std::unary_function的使用已被取代。
但它继续使用std::unary_function作为默认值,只要它没有被检测到被删除。
从Boost 1.80开始,当使用C11或更高版本的libstdccommitissue)时,std::unary_function的使用被禁用,以消除弃用警告,并且已经为libc++(commitissue)合并了一个类似的补丁。后者似乎没有包含在1.80版本中,但包含在1.81中。
因此,要么你等待/升级到最新版本的Boost,手动添加补丁,要么将头文件配置为系统头文件,这样它们的警告通常会被抑制。(我不确定这在你的设置中是否完全可能。)或者用你正在显示的标志禁用弃用警告,但这似乎很笨拙。
在C++17或更高版本的模式下编译,其中函数已被完全删除,也可能会有所帮助(尚未测试)。
在包含任何boost头之前简单地定义宏BOOST_NO_CXX98_FUNCTION_BASE也可能会有帮助,但我不知道它是否是为了让用户这样做,或者它是否会破坏其他boost内容。据我所知,它也可能会默默地破坏ABI。

相关问题