Ticket #8642: ticket8642.cpp

File ticket8642.cpp, 962 bytes (added by Andrey Semashev, 8 years ago)

A testcase to reproduce the problem

Line 
1#include <string>
2#include <boost/config.hpp>
3#include <boost/shared_ptr.hpp>
4#include <boost/filesystem/path.hpp>
5
6// Make sure boost::filesystem::path invokes code conversion
7#if defined(BOOST_WINDOWS)
8typedef std::string path_string;
9path_string foo_path = "foo.txt";
10#else
11typedef std::wstring path_string;
12path_string foo_path = L"foo.txt";
13#endif
14
15struct sink
16{
17 path_string m_path;
18
19 void foo()
20 {
21 boost::filesystem::path p(m_path);
22 }
23};
24
25struct core
26{
27 boost::shared_ptr< sink > m_sink;
28
29 ~core()
30 {
31 if (m_sink)
32 m_sink->foo();
33 }
34
35 static boost::shared_ptr< core > get_instance()
36 {
37 static boost::shared_ptr< core > instance;
38 if (!instance)
39 instance.reset(new core());
40 return instance;
41 }
42};
43
44int main()
45{
46 boost::shared_ptr< core > c = core::get_instance();
47 c->m_sink.reset(new sink());
48 // Initialize the path locale after the core instance
49 c->m_sink->m_path = boost::filesystem::path(foo_path).string< path_string >();
50 return 0;
51}