Boost C++ Libraries: Ticket #12243: Boost.Serialization compilation error in Visual Studio with Zc:wchar_t- https://svn.boost.org/trac10/ticket/12243 <p> The error is following: </p> <pre class="wiki">C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\INCLUDE\limits(85) : error C2090: function returns array H:\Third_party_src\boost\boost_1_61_0-compiled\boost/archive/basic_text_oprimitive.hpp(147) : see reference to class template instantiation 'std::numeric_limits&lt;_Ty&gt;' being compiled with [ _Ty=const unsigned short [24] ] H:\Third_party_src\boost\boost_1_61_0-compiled\boost/archive/basic_text_oprimitive.hpp(180) : see reference to class template instantiation 'boost::archive::basic_text_oprimitive&lt;OStream&gt;::is_float&lt;T&gt;' being compiled with [ OStream=std::wostream, T=const unsigned short [24] ] H:\Third_party_src\boost\boost_1_61_0-compiled\boost/archive/xml_woarchive.hpp(73) : see reference to function template instantiation 'void boost::archive::basic_text_oprimitive&lt;OStream&gt;::save&lt;const unsigned short[24]&gt;(T (&amp;))' being compiled with [ OStream=std::wostream, T=const unsigned short [24] ] H:\Third_party_src\boost\boost_1_61_0-compiled\boost/archive/xml_woarchive.hpp(73) : see reference to function template instantiation 'void boost::archive::basic_text_oprimitive&lt;OStream&gt;::save&lt;const unsigned short[24]&gt;(T (&amp;))' being compiled with [ OStream=std::wostream, T=const unsigned short [24] ] H:\Third_party_src\boost\boost_1_61_0-compiled\boost/archive/impl/xml_woarchive_impl.ipp(144) : see reference to function template instantiation 'void boost::archive::xml_woarchive_impl&lt;Archive&gt;::save&lt;const unsigned short[24]&gt;(T (&amp;))' being compiled with [ Archive=boost::archive::xml_woarchive, T=const unsigned short [24] ] ............................... </pre><p> The problem is with <strong>boost/archive/impl/xml_woarchive_impl.ipp(144)</strong> line: </p> <pre class="wiki"> save(L"&lt;/boost_serialization&gt;\n"); </pre><p> It's fixed by replacing line with </p> <pre class="wiki"> save((const wchar_t*)L"&lt;/boost_serialization&gt;\n"); </pre><p> Interesting error, as it treats the literal L"&lt;/boost_serialization&gt;\n" as 'const unsigned short <a class="changeset" href="https://svn.boost.org/trac10/changeset/24" title="*** empty log message *** ">[24]</a>' and picks </p> <pre class="wiki">template&lt;class T&gt; void save(const T &amp; t){ basic_text_oprimitive&lt;std::wostream&gt;::save(t); } </pre><p> from <strong>boost/archive/xml_woarchive.hpp</strong> , instead of correct </p> <pre class="wiki"> #ifndef BOOST_NO_INTRINSIC_WCHAR_T BOOST_WARCHIVE_DECL void save(const wchar_t * t); #endif </pre><p> And... If we remove the </p> <pre class="wiki"> #ifndef BOOST_NO_INTRINSIC_WCHAR_T </pre><p> everything (including /Zc:wchar_t and /Zc:wchar_t- configurations) compiles fine. </p> <p> <strong>So the actual bug is this 'ifndef'.</strong> </p> <p> Why it was placed here? Most likely by mistake. </p> <p> Please remove this 'ifndef'. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12243 Trac 1.4.3 anonymous Wed, 01 Jun 2016 15:50:28 GMT <link>https://svn.boost.org/trac10/ticket/12243#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12243#comment:1</guid> <description> <p> I searched the boost code a bit and came to conclusion that you should use </p> <pre class="wiki"> #ifndef BOOST_NO_CWCHAR </pre><p> for functions that accept wchar_t literals. </p> <p> Otherwise the function <strong>xml_woarchive_impl::save</strong> (and similar functions) won't work with wchar_t literals in Visual Studio with /Zc:wchar_t- . </p> <p> The Boost.Serialization compilation error is a side effect of this oversight. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 01 Jun 2016 16:04:38 GMT</pubDate> <title>component changed; owner set https://svn.boost.org/trac10/ticket/12243#comment:2 https://svn.boost.org/trac10/ticket/12243#comment:2 <ul> <li><strong>owner</strong> set to <span class="trac-author">Robert Ramey</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">serialization</span> </li> </ul> Ticket Robert Ramey Tue, 01 Nov 2016 22:52:41 GMT <link>https://svn.boost.org/trac10/ticket/12243#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12243#comment:3</guid> <description> <p> could you expand a little on this? Where should the define go? I'm getting that there is no fix called for in the serialization library itself. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Robert Ramey</dc:creator> <pubDate>Thu, 04 May 2017 20:04:19 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12243#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12243#comment:4</guid> <description> <p> So the actual bug is this 'ifndef'. </p> <p> Why it was placed here? Most likely by mistake. </p> <p> nope - removing it will result in compile errors on platforms which don't define wchar_t </p> <p> according to documentation on boost.config, BOOST_NO_CWCHAR is meant to indicate that the platform doesn't have headers for &lt;wchar.h&gt; and &lt;cwchar&gt; so that's not a great choice either </p> <p> And... If we remove the </p> <blockquote> <p> remove #ifndef BOOST_NO_INTRINSIC_WCHAR_T </p> </blockquote> <p> everything (including /Zc:wchar_t and /Zc:wchar_t- configurations) compiles fine. </p> <p> I can't see how this would actually work </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 06 Jun 2017 12:32:12 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12243#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12243#comment:5</guid> <description> <p> I couldn't modify the bug description, so I placed additional info in the follow-up comment, so please read it. </p> <p> In short, you should replace the uses of </p> <blockquote> <p> #ifndef BOOST_NO_INTRINSIC_WCHAR_T </p> </blockquote> <p> with </p> <blockquote> <p> #ifndef BOOST_NO_CWCHAR </p> </blockquote> <p> in several headers. (Othervise some functions for wchar_t will not be declared in /Zc:wchar_t- configuration.) </p> <p> Such replacement would be consistent with other function declarations across boost, where type wchar_t is required (whether intrinsic of typedef'd). The macro BOOST_NO_INTRINSIC_WCHAR_T in these headers was used incorrectly, because the BOOST_NO_CWCHAR was actually meant. </p> <p> The configuration /Zc:wchar_t- seems not to be properly tested in boost, as can be concluded from existence of this bug. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Tue, 13 Jun 2017 17:10:38 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/12243#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12243#comment:6</guid> <description> <p> Sorry to confuse things but there are actually 3 distinct and completely orthogonal configuration macros here, and it appears serialization may need all 3: </p> <p> BOOST_NO_INTRINSIC_WCHAR_T: Use when you are specializing a template or overloading a function on wchar_t <strong>as well as</strong> the other integer types. BOOST_NO_CWCHAR: Use before inclusion of &lt;cwchar&gt; or use of it's functions. BOOST_NO_STD_WSTRING: Use before use of std::wstring. Perversely, presence of this macro does not mean that you cannot at least forward declare basic_string&lt;wchar_t&gt;, but you may not be able to instantiate it (or it's members) without linker errors unless the user has specified some command-line magic. Or to put it another way, you can still use basic_string&lt;wchar_t&gt; in templates that will only be instantiated when actually used: in which situation the user gets what they deserve ;) </p> <p> Note that the presence of one of these does not imply much if anything about the others - for example we have msvc with &lt;cwchar&gt; but wchar_t not a native type, while on gcc wchar_t is always a native type, even though the platform it's building for (early cygwin, some embedded platforms) has no wide character functions. </p> <p> There is one final conundrum that only Robert can decide on - if wchar_t is not a distinct type, and integer and character types are to be handled differently, what is the library supposed to do exactly when presented with an unsigned short? We have no way of knowing whether it's a character or an integer. Special treatment for wchar_t* seems sensible though since there is no special overload for unsigned short*. </p> <p> I'm not going to go through the whole codebase and suggest which should be used where (but let me know if you need help testing this specific configuration), but my suggestion would be: </p> <p> load/save overloaded on wchar_t* : use BOOST_NO_CWCHAR, ditto in the implementation. load/save overloaded on wchar_t : maybe check for both BOOST_NO_INTRINSIC_WCHAR_T and BOOST_NO_CWCHAR. </p> <p> HTH. </p> </description> <category>Ticket</category> </item> </channel> </rss>