How to silence internal boost deprecated messages

Viewed 1167

I'm porting my code from boost 1.67 to boost 1.74 (debian buster->bullseye).

When I compile I get:

In file included from /usr/include/boost/config/header_deprecated.hpp:18,
                 from /usr/include/boost/detail/no_exceptions_support.hpp:15,
                 from /usr/include/boost/msm/back/state_machine.hpp:20,
                 from /home/stew/mycode.cpp:3:
/usr/include/boost/detail/no_exceptions_support.hpp:17:1: note: ‘#pragma message: This header is deprecated. Use <boost/core/no_exceptions_support.hpp> instead.’
   17 | BOOST_HEADER_DEPRECATED("<boost/core/no_exceptions_support.hpp>")
      | ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/boost/bind.hpp:36:1: note: ‘#pragma message: The practice of declaring the Bind placeholders (_1, _2, ...) in the global namespace is deprecated. Please use <boost/bind/bind.hpp> + using namespace boost::placeholders, or define BOOST_BIND_GLOBAL_PLACEHOLDERS to retain the current behavior.’
   36 | BOOST_PRAGMA_MESSAGE(
      | ^~~~~~~~~~~~~~~~~~~~

I get that headers get deprecated. I'm happy to change

#include <boost/bind.hpp>                         -> #include <boost/bind/bind.hpp>
#include <boost/detail/no_exceptions_support.hpp> -> #include <boost/core/no_exceptions_support.hpp>

However the problem isn't in my code. It's in <boost/msm/back/state_machine.hpp>. I'm getting errors like these for each instance of including any of these headers:

In file included from /usr/include/boost/bind.hpp:30,
                 from /usr/include/boost/property_tree/json_parser/detail/parser.hpp:7,
                 from /usr/include/boost/property_tree/json_parser/detail/read.hpp:13,
                 from /usr/include/boost/property_tree/json_parser.hpp:16:
/usr/include/boost/bind.hpp:36:1: note: ‘#pragma message: The practice of declaring the Bind placeholders (_1, _2, ...) in the global namespace is deprecated. Please use <boost/bind/bind.hpp> + using namespace boost::placeholders, or define BOOST_BIND_GLOBAL_PLACEHOLDERS to retain the current behavior.’
   36 | BOOST_PRAGMA_MESSAGE(
      | ^~~~~~~~~~~~~~~~~~~~


In file included from /usr/include/boost/math/tools/cxx03_warn.hpp:9,
                 from /usr/include/boost/math/constants/constants.hpp:11:
/usr/include/boost/bind.hpp:36:1: note: ‘#pragma message: The practice of declaring the Bind placeholders (_1, _2, ...) in the global namespace is deprecated. Please use <boost/bind/bind.hpp> + using namespace boost::placeholders, or define BOOST_BIND_GLOBAL_PLACEHOLDERS to retain the current behavior.’
   36 | BOOST_PRAGMA_MESSAGE(
      | ^~~~~~~~~~~~~~~~~~~~


In file included from /usr/include/boost/smart_ptr/detail/sp_thread_sleep.hpp:22,
                 from /usr/include/boost/smart_ptr/detail/yield_k.hpp:23,
                 from /usr/include/boost/smart_ptr/detail/spinlock_gcc_atomic.hpp:14,
                 from /usr/include/boost/smart_ptr/detail/spinlock.hpp:42,
                 from /usr/include/boost/smart_ptr/detail/spinlock_pool.hpp:25,
                 from /usr/include/boost/smart_ptr/shared_ptr.hpp:29,
                 from /usr/include/boost/shared_ptr.hpp:17,
                 from /usr/include/boost/date_time/time_clock.hpp:17,
                 from /usr/include/boost/date_time/posix_time/posix_time_types.hpp:10,
                 from /usr/include/boost/asio/time_traits.hpp:23,
                 from /usr/include/boost/asio/detail/timer_queue_ptime.hpp:22,
                 from /usr/include/boost/asio/detail/deadline_timer_service.hpp:29,
                 from /usr/include/boost/asio/basic_deadline_timer.hpp:25,
                 from /usr/include/boost/asio.hpp:25:
/usr/include/boost/bind.hpp:36:1: note: ‘#pragma message: The practice of declaring the Bind placeholders (_1, _2, ...) in the global namespace is deprecated. Please use <boost/bind/bind.hpp> + using namespace boost::placeholders, or define BOOST_BIND_GLOBAL_PLACEHOLDERS to retain the current behavior.’
   36 | BOOST_PRAGMA_MESSAGE(
      | ^~~~~~~~~~~~~~~~~~~~

Is there a way to silence boost's internal warnings without patching boost itself?

I know I can -DBOOST_BIND_GLOBAL_PLACEHOLDERS to avoid the bind warning, but what about the detail/no_exceptions_support.hpp issue?

2 Answers

You can

  • tell the library devs that the warnings are disruptive. The 'downstream' libraries should be updating to avoid the deprecated interface(s)

  • look up workarounds for individual messages. E.g. globally adding the BOOST_BIND_GLOBAL_PLACEHOLDERS define will silence all the bind.hpp warnings. Technically, you should prefer to use BOOST_BIND_NO_PLACEHOLDERS but some libraries wouldn't work anymore (e.g. Boost Property Tree, at least for some backends).

This has been driving me crazy too. I finally just modified the internally referenced boost include files per the instruction. In my case it was just four files and for most it was just a matter of commenting out unnecessary includes. The files I modified are

  • boost\geometry\index\detail\varray_detail.hpp
  • boost\chrono\io\time_point_io.hpp
  • boost\chrono\io\duration_io.hpp
  • boost\range\metafunctions.hpp
Related