Boost C++ Libraries: Ticket #4100: some boost classes have sizeof that depends on NDEBUG https://svn.boost.org/trac10/ticket/4100 <p> In boost 1.42: </p> <p> 1) boost::range_iterator: range/iterator_range.hpp: </p> <blockquote> <p> #ifndef NDEBUG bool singular; #endif </p> </blockquote> <p> Seems already fixed in trunk </p> <p> 2) boost::circular_buffer: circular_buffer/base.hpp: </p> <p> template &lt;class T, class Alloc&gt; class circular_buffer /*! \cond */ #if BOOST_CB_ENABLE_DEBUG : public cb_details::debug_iterator_registry #endif </p> <p> 3) statechart::detail::id_provider: statechart/detail/rtti_policy.hpp </p> <p> struct id_provider { </p> <blockquote> <p> const void * pCustomId_; </p> <table class="wiki"> <tr>#if defined( BOOST_ENABLE_ASSERT_HANDLER ) <td> !defined( NDEBUG ) </td></tr></table> <p> const std::type_info * pCustomIdType_; #endif </p> </blockquote> <p> }; </p> <p> The problem is rather serious if two binaries that are loaded into the same address space (e.g. a library and a program, or two libraries) are built with different defines (one with NDEBUG, the other without it). </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4100 Trac 1.4.3 Marshall Clow Sun, 06 Jun 2010 15:45:17 GMT component changed; owner set https://svn.boost.org/trac10/ticket/4100#comment:1 https://svn.boost.org/trac10/ticket/4100#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">Jan Gaspar</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">circular_buffer</span> </li> </ul> Ticket Jan Gaspar Mon, 22 Nov 2010 22:14:49 GMT <link>https://svn.boost.org/trac10/ticket/4100#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4100#comment:2</guid> <description> <p> How I am supposed to fix this? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 23 Nov 2010 02:18:08 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4100#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4100#comment:3</guid> <description> <p> Just do not use NDEBUG in headers. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Jan Gaspar</dc:creator> <pubDate>Tue, 23 Nov 2010 19:53:03 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4100#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4100#comment:4</guid> <description> <p> It doesn't make any sense. You would run into the same trouble if one library is compiled with BOOST_CB_DISABLE_DEBUG defined and another without. It is rather a language deficiency than a library bug. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 24 Nov 2010 04:06:27 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4100#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4100#comment:5</guid> <description> <p> I was not 100% correct. In this particular case BOOST_CB_ENABLE_DEBUG (that depends on NDEBUG or BOOST_CB_DISABLE_DEBUG) should not affect sizeof. You can use it to do some additional checks, but sizeof() should always be the same. </p> <p> NDEBUG is quite common macro. It should never affect sizeof. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Wed, 24 Nov 2010 06:01:51 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4100#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4100#comment:6</guid> <description> <p> <em>NDEBUG is quite common macro. It should never affect sizeof.</em> </p> <p> That's quite a assertion. Could you back that up, please? </p> <p> <em>Just do not use NDEBUG in headers.</em> </p> <p> Checking on my system, I find that the C++ standard library shipped with gcc 4.2 uses NDEBUG in headers, as does php and wx-windows. </p> <p> <em>The problem is rather serious if two binaries that are loaded into the same address space (e.g. a library and a program, or two libraries) are built with different defines (one with NDEBUG, the other without it).</em> </p> <p> This is absolutely true - in that case, you would have an <a class="ext-link" href="http://lmgtfy.com/?q=one+definition+rule+c%2B%2B"><span class="icon">​</span>ODR violation</a>. However, I don't think that this is a problem with the boost library, but rather with your build configuration. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Jan Gaspar</dc:creator> <pubDate>Wed, 24 Nov 2010 22:33:02 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4100#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4100#comment:7</guid> <description> <p> The problem is that I want to have circular buffer's debug support automatically enabled in debug mode and disabled in release mode. </p> <p> Let me ask you a question: Suppose the NDEBUG macro does not affect the size but it affects the implementation of the methods only. Now considering your example of two binaries in the same address space - do you think such a program will now work OK? If so then why? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Thu, 25 Nov 2010 03:33:35 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4100#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4100#comment:8</guid> <description> <p> Seems that my last comment is lost: the use-case is that there is a library that uses boost and that I do not have control of. It's not the problem with my build configuration. I do not want to sync my CPPFLAGS with build-time flags for that library. </p> <p> Such depends on quite common macros as NDEBUG is just not good for a general purpose library as boost or STL. </p> <p> Also, I do not see NDEBUG in gcc 4.2 STL headers (as shipped with FreeBSD 8.1) and gcc 4.5 STL headers (as shipped with Debian Squeeze). php and wxWidgets are not general purpose libraries and I would not care about them at all. </p> <p> As for identical in-memory layout but different behavior -- I would not care as long as ABI is not broken. This means that if you have additional members you should implement copy constructors and = operators properly (and other assignments to them) regardless of NDEBUG, but you can do additional checks that use these members in !NDEBUG case. I do not see anything wrong with it. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Jan Gaspar</dc:creator> <pubDate>Fri, 26 Nov 2010 22:26:19 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4100#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4100#comment:9</guid> <description> <p> OK, will fix it then. The debug support won't be turned on by default in the debug mode. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Sylvain Joyeux</dc:creator> <pubDate>Wed, 14 Sep 2011 09:01:00 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4100#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4100#comment:10</guid> <description> <p> Not fixed in trunk. Any plans so far ? </p> </description> <category>Ticket</category> </item> <item> <author>Olaf van der Spek <olafvdspek@…></author> <pubDate>Sat, 01 Oct 2011 12:44:15 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4100#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4100#comment:11</guid> <description> <p> AFAIK VC container sizeof depends on NDEBUG too. I don't think it's reasonable to expect to be able to mix DEBUG and NDEBUG stuff. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Tue, 21 May 2013 18:10:01 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4100#comment:12 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4100#comment:12</guid> <description> <p> There is nothing that say that people can mix debug and not debug modes, so for me this is an invalid ticket. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 09 Jun 2013 20:51:30 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/4100#comment:13 https://svn.boost.org/trac10/ticket/4100#comment:13 <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">invalid</span> </li> </ul> Ticket