Boost logo

Boost :

Subject: [boost] [asio] C++11 conformance problem: tie(this)
From: Howard Hinnant (howard.hinnant_at_[hidden])
Date: 2012-08-14 17:04:11


In three places asio/basic_socket_iostream.hpp does this:

  tie(this);

In C++11 tie(this) has become undefined behavior, due to 27.5.5.3 [basic.ios.members]/p2:

  basic_ostream<charT,traits>* tie(basic_ostream<charT,traits>* tiestr);

  Requires: If tiestr is not null, tiestr must not be reachable by traversing
  the linked list of tied stream objects starting from tiestr->tie().

In libc++ it causes an infinite recursion as the ostream::sentry constructor calls flush on the tied buffer, and flush subsequently constructs a local ostream::sentry object (this is all C++11 required behavior).

I could detect tie(this) in libc++ and ignore it (as a conforming extension). However I can not detect cyclic ties in general. My gut feeling is that a noisy error is better than ignoring it because whatever tie(this) is supposed to be accomplishing in asio, it isn't, at least not with C++11-conforming std::libs (ignore or crash seem to be std::lib's two obvious options).

I believe the best course of action is to remove the three instances of tie(this) from asio. I do not know if this same issue occurs in other parts of boost. I scanned but didn't catch anything.

Howard


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk