Boost C++ Libraries: Ticket #6638: convert_aux fails while intializing global variable https://svn.boost.org/trac10/ticket/6638 <p> <em>path_traits.cpp</em><br /> </p> <p> <strong>convert_aux</strong> fails in global scope:<br /> </p> <p> Trying to initialize global path variable by concatenating '/' a wide string path w/ narrow string path fails! <br /> </p> <p> "Unhandled exception at 0x0f8bc688 (msvcp100d.dll) in paths.exe: 0xC0000005: Access violation reading location 0x00000000." <br /> </p> <p> If initializing inside main() scope everything works fine. I think this worked as expected in previous version(s) 1.48.. no luck with 1.49 though :( <br /> </p> <p> Additional info: WIN 32 and 64 bit, MSVS2010<br /> </p> <pre class="wiki">#include &lt;iostream&gt; #include &lt;boost/filesystem.hpp&gt; using namespace boost::filesystem; path p(L"C:\\TEMP\\"); path q(p / L"wide"); // Works! path r(p / "narrow"); // Breaks :( int _tmain(int argc, _TCHAR* argv[]) { path p(L"C:\\TEMP\\"); path q(p / L"wide"); // Works! path r(p / "narrow"); // Works here! std::cout &lt;&lt; r.string() &lt;&lt; std::endl; return 0; } </pre><p> <br /> </p> <p> P.S. If more info is required I will reply here not by email. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6638 Trac 1.4.3 john doe <johndoe> Wed, 29 Feb 2012 22:47:35 GMT attachment set https://svn.boost.org/trac10/ticket/6638 https://svn.boost.org/trac10/ticket/6638 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">CallStack.txt</span> </li> </ul> <p> Full stack trace </p> Ticket john doe <johndoe> Wed, 29 Feb 2012 22:51:26 GMT attachment set https://svn.boost.org/trac10/ticket/6638 https://svn.boost.org/trac10/ticket/6638 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">paths.cpp</span> </li> </ul> Ticket john doe <johndoe> Wed, 29 Feb 2012 22:53:12 GMT keywords set https://svn.boost.org/trac10/ticket/6638#comment:1 https://svn.boost.org/trac10/ticket/6638#comment:1 <ul> <li><strong>keywords</strong> filesystem path convert wide/narrow string added </li> </ul> Ticket Fraser Hutchison <fraser.hutchison@…> Sun, 11 Mar 2012 14:06:10 GMT <link>https://svn.boost.org/trac10/ticket/6638#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6638#comment:2</guid> <description> <p> It appears to be down to an MSVC bug. </p> <p> The third path constructor calls <code>codecvt()</code>, which calls <code>wchar_t_codecvt_facet()</code>, which returns <code>codecvt_facet</code>. However, <code>codecvt_facet</code> hasn't been initialised at this point. </p> <p> I believe the Standard requires <code>codecvt_facet</code> to have been initialised before <code>wchar_t_codecvt_facet()</code> since it comes earlier in the same translation unit, hence I think this is an MSVC bug. </p> <p> I can confirm that there is no problem with this in 1.48.0 - it's moving <code>codecvt_facet</code> from being a static member to a variable in unnamed namespace in 1.49.0 that has caused the issue. </p> <p> The following slightly simpler program gives the error also: </p> <pre class="wiki">#include "boost/filesystem/v3/path.hpp" boost::filesystem::path p("p"); int main() { return 0; } </pre> </description> <category>Ticket</category> </item> <item> <author>Nils Gladitz <gladitz@…></author> <pubDate>Wed, 14 Mar 2012 09:01:19 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6638#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6638#comment:3</guid> <description> <p> I've got the same problem with Intel 11.1 (+MSVC2005). </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Thu, 22 Mar 2012 18:17:27 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6638#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6638#comment:4</guid> <description> <p> For what it's worth, you can work around this crash bug by reverting changeset 76303. <a class="ext-link" href="https://svn.boost.org/trac/boost/changeset/76303/trunk/libs/filesystem/v3/src/path"><span class="icon">​</span>https://svn.boost.org/trac/boost/changeset/76303/trunk/libs/filesystem/v3/src/path</a>. </p> <p> This change was implemented to fix issue 6320. <a class="ext-link" href="https://svn.boost.org/trac/boost/ticket/6320"><span class="icon">​</span>https://svn.boost.org/trac/boost/ticket/6320</a> </p> </description> <category>Ticket</category> </item> <item> <author>Nils Gladitz <gladitz@…></author> <pubDate>Thu, 05 Sep 2013 09:39:47 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6638#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6638#comment:5</guid> <description> <p> The snippet in the description no longer crashes for me in Boost 1.54.0 but now the following (related?) snippet does: </p> <pre class="wiki">#include &lt;boost/filesystem.hpp&gt; using namespace boost::filesystem; class Test { public: ~Test() { path p(L"C:\\TEMP\\"); path r(p / "narrow"); } }; Test test1; Test test2; int main() { } </pre> </description> <category>Ticket</category> </item> <item> <author>Andrei Ortolan - andrei-fsnt@…</author> <pubDate>Thu, 21 May 2015 22:24:33 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6638#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6638#comment:6</guid> <description> <p> Me too in boost_1_57_0_32_b_vs10 </p> <p> <a class="missing wiki">CheckCreateDir</a>(".\test\test\"); </p> <p> bool <a class="missing wiki">CheckCreateDir</a>(std::string path){ </p> <blockquote> <p> try{ </p> <blockquote> <p> if (boost::filesystem::exists(path)) </p> <blockquote> <p> return true; </p> </blockquote> </blockquote> <p> } catch (const boost::filesystem::filesystem_error&amp; ex){ </p> <blockquote> <p> std::cout &lt;&lt; "\n EX " &lt;&lt; ex.what(); return false; </p> </blockquote> <p> } </p> </blockquote> <p> </p> <blockquote> <p> bool res; try{ </p> <blockquote> <p> res = boost::filesystem::create_directories(path); </p> </blockquote> <p> } catch (...){ </p> <blockquote> <p> return false; </p> </blockquote> <p> } return res; </p> </blockquote> <blockquote> <p> } </p> </blockquote> </description> <category>Ticket</category> </item> <item> <dc:creator>Beman Dawes</dc:creator> <pubDate>Sun, 30 Aug 2015 20:15:12 GMT</pubDate> <title>status, version changed https://svn.boost.org/trac10/ticket/6638#comment:7 https://svn.boost.org/trac10/ticket/6638#comment:7 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> <li><strong>version</strong> <span class="trac-field-old">Boost 1.49.0</span> → <span class="trac-field-new">Boost 1.59.0</span> </li> </ul> <p> The original problem and the example from Fraser Hutchison appear to have been corrected some time ago. </p> <p> The code supplied by Andrei Ortolan works fine for me, once the missing backslashes are added. </p> <p> The code supplied by Nils Gladitz (Test test1; Test test2;) fails for me on static builds. It is not failing for me for shared builds. Tests run only on Windows. </p> <p> There is a simple workaround; add path p("narrow"; before the two Test variables, and it works fine. </p> <p> I'd like to fix the underlying problem, but have not come up with anything workable. So it will stay open for a while longer. </p> <p> Thanks, </p> <p> --Beman </p> <p> </p> Ticket anonymous Mon, 24 Apr 2017 11:40:59 GMT <link>https://svn.boost.org/trac10/ticket/6638#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6638#comment:8</guid> <description> <p> Hi things got worse with this error. I beleive this worked with 1.63. </p> <p> Config: </p> <p> boost-1.64.0, vc14, x64, debug, static lib, statically linked runtime </p> <p> Error: </p> <pre class="wiki">Exception thrown: read access violation. this-&gt;_Ptr-&gt;_Facetvec was 0x111011101110111. If there is a handler for this exception, the program may be safely continued. </pre><p> Code: </p> <pre class="wiki">class Alma { public: ~Alma() { std::cout &lt;&lt; boost::filesystem::path("c:\\alma.txt").string() &lt;&lt; std::endl; } }; static Alma a; int main(int argc, char* argv[]) { return 0; } </pre><p> Call stack: </p> <pre class="wiki">Test.exe!std::locale::_Getfacet(unsigned __int64 _Id) Line 459 C++ Test.exe!std::use_facet&lt;std::codecvt&lt;wchar_t,char,_Mbstatet&gt; &gt;(const std::locale &amp; _Loc) Line 564 C++ Test.exe!boost::filesystem::path::codecvt() Line 940 C++ Test.exe!boost::filesystem::path_traits::convert(const char * from, const char * from_end, std::basic_string&lt;wchar_t,std::char_traits&lt;wchar_t&gt;,std::allocator&lt;wchar_t&gt; &gt; &amp; to) Line 981 C++ Test.exe!boost::filesystem::path_traits::dispatch&lt;std::basic_string&lt;wchar_t,std::char_traits&lt;wchar_t&gt;,std::allocator&lt;wchar_t&gt; &gt; &gt;(const std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; &amp; c, std::basic_string&lt;wchar_t,std::char_traits&lt;wchar_t&gt;,std::allocator&lt;wchar_t&gt; &gt; &amp; to) Line 256 C++ Test.exe!boost::filesystem::path::path&lt;char [12]&gt;(const char[12] &amp; source, void * __formal) Line 144 C++ Test.exe!Alma::~Alma() Line 88 C++ [External Code] Test.exe!_execute_onexit_table::__l22::&lt;lambda&gt;() Line 198 C++ Test.exe!__crt_seh_guarded_call&lt;int&gt;::operator()&lt;void &lt;lambda&gt;(void),int &lt;lambda&gt;(void) &amp; __ptr64,void &lt;lambda&gt;(void) &gt;(__acrt_lock_and_call::__l3::void &lt;lambda&gt;(void) &amp;&amp; setup, _execute_onexit_table::__l22::int &lt;lambda&gt;(void) &amp; action, __acrt_lock_and_call::__l4::void &lt;lambda&gt;(void) &amp;&amp; cleanup) Line 199 C++ Test.exe!__acrt_lock_and_call&lt;int &lt;lambda&gt;(void) &gt;(const __acrt_lock_id lock_id, _execute_onexit_table::__l22::int &lt;lambda&gt;(void) &amp;&amp; action) Line 882 C++ Test.exe!_execute_onexit_table(_onexit_table_t * table) Line 222 C++ Test.exe!common_exit(const int return_code, const _crt_exit_cleanup_mode cleanup_mode, const _crt_exit_return_mode return_mode) Line 211 C++ Test.exe!exit(int return_code) Line 283 C++ </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 24 Apr 2017 12:24:07 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6638#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6638#comment:9</guid> <description> <p> I made two error in my report: </p> <p> There has to be an instantiation of the test class in the main, too: </p> <pre class="wiki">class Alma { public: ~Alma() { std::cout &lt;&lt; boost::filesystem::path("c:\\alma.txt").string() &lt;&lt; std::endl; } }; static Alma a; int main(int argc, char* argv[]) { Alma(); //without this there is no crash return 0; } </pre><p> It is an error with 1.63 as well. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 24 Apr 2017 16:54:46 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6638#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6638#comment:10</guid> <description> <p> This version does not crash (but it does if I removed the constructor code): </p> <pre class="wiki">class Alma { public: Alma() { boost::filesystem::exists("C:\\alma.txt"); } ~Alma() { std::cout &lt;&lt; boost::filesystem::path("c:\\alma.txt").string() &lt;&lt; std::endl; } }; Alma a; int main(int argc, char* argv[]) { Alma(); return 0; } </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>Leinad</dc:creator> <pubDate>Tue, 25 Apr 2017 12:09:35 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6638#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6638#comment:11</guid> <description> <p> Here is another crashing variation: </p> <pre class="wiki">#include &lt;boost\filesystem.hpp&gt; class Alma { public: Alma() { /*boost::filesystem::exists("C:\\alma.txt");*/ } ~Alma() { std::cout &lt;&lt; boost::filesystem::path("c:\\alma.txt").string() &lt;&lt; std::endl; } }; class Korte { public: Korte() { boost::filesystem::exists("C:\\korte.txt"); } ~Korte() { std::cout &lt;&lt; boost::filesystem::path("c:\\korte.txt").string() &lt;&lt; std::endl; } }; Alma a; Korte k; int main(int argc, char* argv[]) { return 0; } </pre><p> Please note that the constructor body of Alma is empty. </p> <p> I wonder whether we could learn from these examples. </p> <p> In this case first <code>a</code>, then the static std local and facet stuff, then <code>k</code> created. Then at exit <code>k</code> destructed, then the static std local and facet stuff, then <code>a</code>. When <code>a</code> is destructed all the facet stuff is gone and that is why it crashes. Wouldn't it be better that in the path.hpp (or where it is appropriate) we had a static std::local instance instead of creating it lazily in the std::locale&amp; path_locale() function? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Leinad</dc:creator> <pubDate>Tue, 25 Apr 2017 17:43:24 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6638#comment:12 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6638#comment:12</guid> <description> <p> I tried it and it seems to work. </p> <p> In path.cpp in the unnamed namespace (the last one for "local helpers") I added <code>std::locale def_locale = default_locale();</code>. Also in the unnamed namespace I altered <code>std::locale&amp; path_locale()</code>: it simply returns the newly added <code>def_locale</code>. That's it. No crash any more. </p> <p> I hope this helps to close this 5-year old bug. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Leinad</dc:creator> <pubDate>Wed, 26 Apr 2017 16:12:09 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6638#comment:13 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6638#comment:13</guid> <description> <p> Well, it seems to work, but... </p> <ol><li>It would not address the concerns about exceptions might be thrown on POSIX systems. </li><li>I am not at all sure about that the static initialisation that the previous solution relies on always happens in that order. </li></ol><p> There is a little trick though that probably solves all our problems. </p> <p> At the end of path.hpp we could create a static instance of a reference to codecvt_type in the unnamed namespace: </p> <pre class="wiki">... namespace { const boost::filesystem::path::codecvt_type&amp; cvt = boost::filesystem::path::codecvt(); } ... </pre><p> In this case in each compilation unit where path.hpp included we would have a separate <code>cvt</code>. In a translation unit static initialisation always occurs in the order of the definition of the objects with static storage duration. Calling <code>codecvt()</code> 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: </p> <pre class="wiki">#include &lt;boost/path.hpp&gt; class Alma { public: ~Alma() { boost::filesystem::path("c:\\alma.txt").string(); } }; static Alma a; int main(int argc, char* argv[]) { Alma(); return 0; } </pre><p> <code>a</code> is created after <code>cvt</code> and destructed before it. </p> </description> <category>Ticket</category> </item> </channel> </rss>