Boost C++ Libraries: Ticket #6182: lexical_cast: invalid application of 'sizeof' to incomplete type 'removed_ptr_t' https://svn.boost.org/trac10/ticket/6182 <p> This is triggered by use of incomplete types, as in the following code: </p> <pre class="wiki">#include &lt;boost/lexical_cast.hpp&gt; #include &lt;iostream&gt; struct ble; typedef struct ble *meh; std::ostream &amp; operator &lt;&lt;(std::ostream &amp;o, meh m) { o &lt;&lt; "yay"; } int main(int argc, char *argv[]) { meh heh; std::cout &lt;&lt; boost::lexical_cast&lt;std::string&gt;(heh) &lt;&lt; std::endl; } </pre><p> This used to work as expected with boost 1.46.1. With boost 1.48.0, the compilation fails with the following message: </p> <pre class="wiki">In file included from x.cc:1:0: /usr/include/boost/lexical_cast.hpp: In static member function 'static Target boost::detail::lexical_cast_do_cast&lt;Target, Source&gt;::lexical_cast_impl(const Source&amp;) [with Target = std::basic_string&lt;char&gt;, Source = ble*]': /usr/include/boost/lexical_cast.hpp:1916:50: instantiated from 'Target boost::lexical_cast(const Source&amp;) [with Target = std::basic_string&lt;char&gt;, Source = ble*]' x.cc:16:52: instantiated from here /usr/include/boost/lexical_cast.hpp:1742:25: error: invalid application of 'sizeof' to incomplete type 'removed_ptr_t {aka ble}' </pre><p> The compiler used is GCC 4.6.1, and I imagine that others would be impacted, too. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6182 Trac 1.4.3 pmachata@… Tue, 29 Nov 2011 00:50:19 GMT attachment set https://svn.boost.org/trac10/ticket/6182 https://svn.boost.org/trac10/ticket/6182 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">boost-1.48.0-lexical_cast-incomplete.patch</span> </li> </ul> <p> Proposed fix </p> Ticket anonymous Tue, 29 Nov 2011 00:51:49 GMT <link>https://svn.boost.org/trac10/ticket/6182#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6182#comment:1</guid> <description> <p> About the proposed fix. To decide whether source type is char, you first ask whether it's char or wchar, and then compare sizeofs. I think the same can be achieved by simply asking whether src is char. I might be missing something though. That's what the patch implements. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 29 Nov 2011 01:26:37 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6182#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6182#comment:2</guid> <description> <p> The bug is also present in svn trunk. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Antony Polukhin</dc:creator> <pubDate>Wed, 04 Jan 2012 16:02:17 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6182#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6182#comment:3</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/6182#comment:1" title="Comment 1">anonymous</a>: </p> <blockquote class="citation"> <p> About the proposed fix. To decide whether source type is char, you first ask whether it's char or wchar, and then compare sizeofs. I think the same can be achieved by simply asking whether src is char. I might be missing something though. That's what the patch implements. </p> </blockquote> <p> The problem here, is that we have char, unsigned char, signed char, wchar_t, char16_t and char32_t types (not only char). And we still need to construct stringbuffer for char types with different sizes.<br /> <br /> Great thanks for bug report and for giving ideas for it fixing. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Antony Polukhin</dc:creator> <pubDate>Wed, 04 Jan 2012 16:03:06 GMT</pubDate> <title>owner, status changed https://svn.boost.org/trac10/ticket/6182#comment:4 https://svn.boost.org/trac10/ticket/6182#comment:4 <ul> <li><strong>owner</strong> changed from <span class="trac-author">nasonov</span> to <span class="trac-author">Antony Polukhin</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket Antony Polukhin Wed, 04 Jan 2012 16:06:43 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/6182#comment:5 https://svn.boost.org/trac10/ticket/6182#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/76305" title="Fixes #6132 Fixes #6182">[76305]</a>) Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6132" title="#6132: Bugs: lexical_cast with Source = void* broken in 1.48.0 (closed: fixed)">#6132</a> Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6182" title="#6182: Bugs: lexical_cast: invalid application of 'sizeof' to incomplete type ... (closed: fixed)">#6182</a> </p> Ticket