Re: [Boost-bugs] [Boost C++ Libraries] #11633: chrono IO may throw bad_cast

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #11633: chrono IO may throw bad_cast
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2015-09-10 08:08:31


#11633: chrono IO may throw bad_cast
--------------------------------------------------+----------------------
  Reporter: Sébastien Barthélémy <barthelemy@…> | Owner: viboes
      Type: Bugs | Status: assigned
 Milestone: To Be Determined | Component: chrono
   Version: Boost 1.58.0 | Severity: Problem
Resolution: | Keywords:
--------------------------------------------------+----------------------

Comment (by Sébastien Barthélémy <barthelemy@…>):

 Hi Vincente, thank you for answering so quickly.

> I tried with version 2 and I was not able to reproduce the issue. Please
 let me know.

 same here.

> For what I understand std::ios_base::imbue is not thread-safe.
> Version 1 is bugged as it does an imbue if the facet is not present,
 raising possible undefined behavior.
> Version 2 duration operator<< doesn't imbues the facet by itself. If not
 present, it uses duration_put.

 would it be possible to fix v1? Maybe with something like this (untested):

 {{{
 template <class CharT, class Traits, class Rep, class Period>
 std::basic_ostream<CharT, Traits>&
 operator<<(std::basic_ostream<CharT, Traits>& os, const duration<Rep,
 Period>& d)
 {
     typedef duration_punct<CharT> Facet;
     os << d.count() << ' ';
     try {
         os << std::use_facet<Facet>(os.getloc()).template
 name<Period>(d.count());
     } catch (std::bad_cast) {
        // os locale does not have the facet
        os << Facet().template name<Period>(d.count());
     }
     return os;
 }
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/11633#comment:5>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:19 UTC