Boost C++ Libraries: Ticket #7299: Spirit Karma static assert with unicode enabled on Win32 and Win64 https://svn.boost.org/trac10/ticket/7299 <p> The following code causes a static assert in boost/spirit/home/karma/detail/output_iterator.hpp. The problem is that buffer_sink stores charactes in a std::basic_string&lt;wchar_t&gt;, but when BOOST_SPIRIT_UNICODE is defined, the output character size is 32-bit. On Windows, wchar_t is 16-bit, which will always hit the static assert. On Linux, wchar_t is 32-bit so we don't have the issue. </p> <div class="wiki-code"><div class="code"><pre><span class="cp">#ifndef BOOST_SPIRIT_UNICODE</span> <span class="cp">#define BOOST_SPIRIT_UNICODE</span> <span class="cp">#endif</span> <span class="cp">#include</span> <span class="cpf">&lt;boost/config/warning_disable.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/spirit/home/qi.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/spirit/home/karma.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;string&gt;</span><span class="cp"></span> <span class="k">namespace</span> <span class="n">karma</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">spirit</span><span class="o">::</span><span class="n">karma</span><span class="p">;</span> <span class="k">template</span><span class="o">&lt;</span><span class="k">typename</span> <span class="n">OutputIterator</span><span class="o">&gt;</span> <span class="k">struct</span> <span class="nl">unicode_char_</span> <span class="p">:</span> <span class="k">public</span> <span class="n">karma</span><span class="o">::</span><span class="n">grammar</span><span class="o">&lt;</span><span class="n">OutputIterator</span><span class="p">,</span> <span class="o">::</span><span class="n">boost</span><span class="o">::</span><span class="n">spirit</span><span class="o">::</span><span class="n">char_encoding</span><span class="o">::</span><span class="n">unicode</span><span class="o">::</span><span class="n">char_type</span><span class="p">()</span><span class="o">&gt;</span> <span class="p">{</span> <span class="n">unicode_char_</span><span class="p">()</span> <span class="o">:</span> <span class="n">base_type</span><span class="p">(</span><span class="n">thechar</span><span class="p">)</span> <span class="p">{</span> <span class="k">using</span> <span class="n">karma</span><span class="o">::</span><span class="n">unicode</span><span class="o">::</span><span class="n">char_</span><span class="p">;</span> <span class="n">thechar</span> <span class="o">=</span> <span class="n">char_</span><span class="p">;</span> <span class="p">}</span> <span class="n">karma</span><span class="o">::</span><span class="n">rule</span><span class="o">&lt;</span><span class="n">OutputIterator</span><span class="p">,</span> <span class="o">::</span><span class="n">boost</span><span class="o">::</span><span class="n">spirit</span><span class="o">::</span><span class="n">char_encoding</span><span class="o">::</span><span class="n">unicode</span><span class="o">::</span><span class="n">char_type</span><span class="p">()</span><span class="o">&gt;</span> <span class="n">thechar</span><span class="p">;</span> <span class="p">};</span> <span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span> <span class="k">typedef</span> <span class="n">std</span><span class="o">::</span><span class="n">basic_string</span><span class="o">&lt;</span><span class="n">boost</span><span class="o">::</span><span class="n">spirit</span><span class="o">::</span><span class="n">char_encoding</span><span class="o">::</span><span class="n">unicode</span><span class="o">::</span><span class="n">char_type</span><span class="o">&gt;</span> <span class="n">unicode_string</span><span class="p">;</span> <span class="k">typedef</span> <span class="n">std</span><span class="o">::</span><span class="n">back_insert_iterator</span><span class="o">&lt;</span><span class="n">unicode_string</span><span class="o">&gt;</span> <span class="n">unicode_back_insert_iterator_type</span><span class="p">;</span> <span class="n">unicode_string</span> <span class="n">input</span><span class="p">;</span> <span class="n">unicode_string</span> <span class="n">output</span><span class="p">;</span> <span class="n">unicode_back_insert_iterator_type</span> <span class="n">insert_iter</span><span class="p">(</span><span class="n">output</span><span class="p">);</span> <span class="n">unicode_char_</span><span class="o">&lt;</span><span class="n">unicode_back_insert_iterator_type</span><span class="o">&gt;</span> <span class="n">unichar</span><span class="p">;</span> <span class="n">karma</span><span class="o">::</span><span class="n">generate</span><span class="p">(</span><span class="n">insert_iter</span><span class="p">,</span><span class="n">unichar</span><span class="p">,</span><span class="n">input</span><span class="p">);</span> <span class="k">return</span> <span class="mi">0</span><span class="p">;</span> <span class="p">}</span> </pre></div></div> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7299 Trac 1.4.3 Joel de Guzman Tue, 28 Aug 2012 11:39:07 GMT owner changed https://svn.boost.org/trac10/ticket/7299#comment:1 https://svn.boost.org/trac10/ticket/7299#comment:1 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Joel de Guzman</span> to <span class="trac-author">Hartmut Kaiser</span> </li> </ul> Ticket Dave Bailey <David.Bailey@…> Wed, 29 Aug 2012 18:02:48 GMT attachment set https://svn.boost.org/trac10/ticket/7299 https://svn.boost.org/trac10/ticket/7299 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">output_iterator.hpp.patch</span> </li> </ul> Ticket Dave Bailey <David.Bailey@…> Wed, 29 Aug 2012 18:04:17 GMT <link>https://svn.boost.org/trac10/ticket/7299#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7299#comment:2</guid> <description> <p> I've attached a patch that solves the problem. It's not particularly elegant but seems to do the job. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Joel de Guzman</dc:creator> <pubDate>Sat, 24 Nov 2018 05:06:34 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7299#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7299#comment:3</guid> <description> <p> fixed in<a class="ext-link" href="https://github.com/boostorg/spirit/commit/3ba8b8b8ed3a88ea2ba168379d019dbb9c4a4e77"><span class="icon">​</span>https://github.com/boostorg/spirit/commit/3ba8b8b8ed3a88ea2ba168379d019dbb9c4a4e77</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Joel de Guzman</dc:creator> <pubDate>Sat, 24 Nov 2018 05:06:54 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/7299#comment:4 https://svn.boost.org/trac10/ticket/7299#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> Ticket