Re: [Boost-bugs] [Boost C++ Libraries] #6638: convert_aux fails while intializing global variable

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #6638: convert_aux fails while intializing global variable
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2017-04-26 16:12:09


#6638: convert_aux fails while intializing global variable
-------------------------+-------------------------------------------------
  Reporter: john doe | Owner: bemandawes
  <johndoe> | Status: assigned
      Type: Bugs | Component: filesystem
 Milestone: To Be | Severity: Problem
  Determined | Keywords: filesystem path convert wide/narrow
   Version: Boost | string
  1.59.0 |
Resolution: |
-------------------------+-------------------------------------------------

Comment (by Leinad):

 Well, it seems to work, but...

 1. It would not address the concerns about exceptions might be thrown on
 POSIX systems.
 2. I am not at all sure about that the static initialisation that the
 previous solution relies on always happens in that order.

 There is a little trick though that probably solves all our problems.

 At the end of path.hpp we could create a static instance of a reference to
 codecvt_type in the unnamed namespace:

 {{{
 ...
 namespace
 {
         const boost::filesystem::path::codecvt_type& cvt =
 boost::filesystem::path::codecvt();
 }
 ...
 }}}

 In this case in each compilation unit where path.hpp included we would
 have a separate {{{cvt}}}. In a translation unit static initialisation
 always occurs in the order of the definition of the objects with static
 storage duration. Calling {{{codecvt()}}} would cause the lazy
 initialisation of the locale and the facet stuff. After that any static
 instance that uses codecvt in its destructor would be safe to use:

 {{{
 #include <boost/path.hpp>

 class Alma
 {
 public:
         ~Alma() { boost::filesystem::path("c:\\alma.txt").string(); }
 };

 static Alma a;

 int main(int argc, char* argv[])
 {
         Alma();
         return 0;
 }
 }}}

 {{{a}}} is created after {{{cvt}}} and destructed before it.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/6638#comment:13>
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-04-26 16:16:59 UTC