Boost logo

Boost Users :

Subject: [Boost-users] [asio][bind] Access violation with placeholders used by static objects
From: Olivier Sauvageau (olivier.sauvageau_at_[hidden])
Date: 2015-04-15 16:32:56


Hello,

I had an access violation issue using boost::asio::placeholders::error as
parameter to boost::bind in a class that was used as type for a static
class member object. I realized that the placeholders, both those in Asio
and those in Bind (e.g., _1) are themselves static objects, and thus found
out that my problem was due to the famous undefined order of initialization
of static objects.

I was able to fix my problem simply by encapsulating my static object in a
function and making sure it's called only after main() has started.
However, I'm still wondering, has this issue ever been discussed and any
correction or alternative proposed? I couldn't find anything on the topic.

On the other hand, I noticed that Asio's placeholders are initialized from
functions, e.g. from <boost/asio/placeholders.hpp>:

  boost::arg<1>& error
    = boost::asio::placeholders::detail::placeholder<1>::get();

Using that function instead could be an alternative, but since it is not in
the "public" namespace and is not in the library documentation, using it
would not be a good idea for maintainability.

Finally, is there any documentation stating the fact that placeholders such
as boost::asio::placeholders::error and _1 are static? I can't find any in
the Asio or Bind documentation, and I feel this is a limitation that should
at least be documented.

Thank you,

-- 
Olivier Sauvageau


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net