简体   繁体   中英

boost program-options uses deprecated feature

I have boost-program-options version 1.78 installed via vcpkg. When I compile with clang++ and -std=c++20 I get the following errors. This doesn't happen when I compile with g++ . According to this this std::unary_function is deprecated as of 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__))

Why is boost using deprecated parts of the standard? Is there anything wrong with ignoring these warnings and suppressing with -Wno-deprecated-declarations ?

The use of std::unary_function has been replaced for compilers/standard libraries not supporting it anymore since Boost 1.64 for MSVC ( commit ) and since 1.73 for other compilers ( commit ).

But it continued using std::unary_function as default as long as it was not detected as removed.

Since Boost 1.80 the use of std::unary_function is disabled when using C++11 or later with libstdc++ ( commit , issue ) to get rid of deprecation warnings and a similar patch has been merged for libc++ ( commit , issue ). The latter seems to not be included in the lastest release 1.80.

So either you wait/upgrade to a recent version of Boost, add the patch manually or configure the inclusion of the headers as system headers, so that warnings for them are generally suppressed. (I am not sure whether this is completely possible in your setup.) Alternatively disable the deprecation warning with the flag you are showing, but that seems heavy-handed.

Compiling in C++17 mode or later where the function has been completely removed might also help (haven't tested).

Simply defining the macro BOOST_NO_CXX98_FUNCTION_BASE before including any boost header might also help, but I can't tell whether it is intended for a user to do that or whether it might break other boost stuff. It may also silently break ABI for all I know.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM