Subject: Re: [Boost-bugs] [Boost C++ Libraries] #8642: Global locale prevents from using Boost.Filesystem in global constructors and destructors
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-10-31 22:16:50
#8642: Global locale prevents from using Boost.Filesystem in global constructors
and destructors
-------------------------------+------------------------
Reporter: andysem | Owner: bemandawes
Type: Bugs | Status: assigned
Milestone: To Be Determined | Component: filesystem
Version: Boost 1.52.0 | Severity: Problem
Resolution: | Keywords:
-------------------------------+------------------------
Comment (by daniel kruegler):
The following example should demonstrate the problem for every currently
supported platform:
{{{
#include "boost/filesystem/path.hpp"
namespace fs = boost::filesystem;
template<class>
struct conv_char;
template<>
struct conv_char<wchar_t>
{
typedef char value_type;
static const value_type* file_name() { return
"abcdefghijklmnopqrst.uvw"; }
};
template<>
struct conv_char<char>
{
typedef wchar_t value_type;
static const value_type* file_name() { return
L"abcdefghijklmnopqrst.uvw"; }
};
typedef conv_char<fs::path::value_type> path_conv_char;
struct A
{
A()
{
}
~A()
{
fs::path pa(path_conv_char::file_name());
}
static A& instance()
{
static A result;
return result;
}
};
struct B
{
B()
{
}
~B()
{
A::instance();
fs::path pb(path_conv_char::file_name());
}
} b;
int main()
{
}
}}}
The code ensures that we perform a code conversion in all cases and takes
advantage of the life-cycle rules of objects with static storage duration.
It gives me a seg fault using gcc and a similar crash for Visual Studio in
the destructor of A. The example provokes that the locale produced by
path_locale() (within path.cpp) is already destroyed when pa becomes
constructed, because by path_locale() holds another function local static.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/8642#comment:4> 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:17 UTC