Boost C++ Libraries: Ticket #5724: "0 + 0" and "0 - 0" lead to a compile time error https://svn.boost.org/trac10/ticket/5724 <p> The following code causes a compilication error under GCC 4.5, 4.6 and VC 10. </p> <pre class="wiki">#define BOOST_RATIO_EXTENSIONS #include &lt;boost/ratio.hpp&gt; using namespace boost; typedef ratio_add&lt;ratio&lt;0&gt;, ratio&lt;0&gt; &gt;::type zero_plus_zero; typedef ratio_subtract&lt;ratio&lt;0&gt;, ratio&lt;0&gt; &gt;::type zero_minus_zero; </pre><p> Error messages (GCC 4.6.0): </p> <pre class="wiki">In file included from C:/Opt/boost/boost/ratio/ratio.hpp:48:0, from C:/Opt/boost/boost/ratio/include.hpp:11, from C:/Opt/boost/boost/ratio.hpp:12, from test.cpp:2: C:/Opt/boost/boost/ratio/detail/overflow_helpers.hpp: In instantiation of 'boost::ratio_detail::ratio_add&lt;boost::ratio&lt;0ll&gt;, boost::ratio&lt;0ll&gt; &gt;': C:/Opt/boost/boost/ratio/ratio.hpp:136:8: instantiated from 'boost::ratio_add&lt;boost::ratio&lt;0ll&gt;, boost::ratio&lt;0ll&gt; &gt;' test.cpp:5:39: instantiated from here C:/Opt/boost/boost/ratio/detail/overflow_helpers.hpp:243:18: error: '(0ll / 0ll)' is not a constant expression C:/Opt/boost/boost/ratio/detail/overflow_helpers.hpp:243:18: note: in template argument for type 'long long int' test.cpp:5:9: error: 'type' in class 'boost::ratio_add&lt;boost::ratio&lt;0ll&gt;, boost::ratio&lt;0ll&gt; &gt;' does not name a type In file included from C:/Opt/boost/boost/ratio/ratio.hpp:48:0, from C:/Opt/boost/boost/ratio/include.hpp:11, from C:/Opt/boost/boost/ratio.hpp:12, from test.cpp:2: C:/Opt/boost/boost/ratio/detail/overflow_helpers.hpp: In instantiation of 'boost::ratio_detail::ratio_subtract&lt;boost::ratio&lt;0ll&gt;, boost::ratio&lt;0ll&gt; &gt;': C:/Opt/boost/boost/ratio/ratio.hpp:142:8: instantiated from 'boost::ratio_subtract&lt;boost::ratio&lt;0ll&gt;, boost::ratio&lt;0ll&gt; &gt;' test.cpp:6:44: instantiated from here C:/Opt/boost/boost/ratio/detail/overflow_helpers.hpp:269:18: error: '(0ll / 0ll)' is not a constant expression C:/Opt/boost/boost/ratio/detail/overflow_helpers.hpp:269:18: note: in template argument for type 'long long int' test.cpp:6:9: error: 'type' in class 'boost::ratio_subtract&lt;boost::ratio&lt;0ll&gt;, boost::ratio&lt;0ll&gt; &gt;' does not name a type </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5724 Trac 1.4.3 iorate <iorate_stage@…> Wed, 20 Jul 2011 12:05:32 GMT component changed; owner set https://svn.boost.org/trac10/ticket/5724#comment:1 https://svn.boost.org/trac10/ticket/5724#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">viboes</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">ratio</span> </li> </ul> Ticket viboes Fri, 19 Aug 2011 15:40:47 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/5724#comment:2 https://svn.boost.org/trac10/ticket/5724#comment:2 <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> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/73918" title="ratio: fix #5724: 0 + 0 and 0 - 0 lead to a compile time error">[73918]</a>) ratio: fix <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/5724" title="#5724: Bugs: &#34;0 + 0&#34; and &#34;0 - 0&#34; lead to a compile time error (closed: fixed)">#5724</a>: 0 + 0 and 0 - 0 lead to a compile time error </p> Ticket viboes Fri, 19 Aug 2011 15:41:12 GMT <link>https://svn.boost.org/trac10/ticket/5724#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5724#comment:3</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/73919" title="ratio: fix #5724: 0 + 0 and 0 - 0 lead to a compile time error">[73919]</a>) ratio: fix <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/5724" title="#5724: Bugs: &#34;0 + 0&#34; and &#34;0 - 0&#34; lead to a compile time error (closed: fixed)">#5724</a>: 0 + 0 and 0 - 0 lead to a compile time error </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 19 Aug 2011 15:43:39 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5724#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5724#comment:4</guid> <description> <p> I have added two partial specialization that solve the issue. </p> <blockquote> <p> template &lt;class R&gt; struct ratio_add&lt;R, ratio&lt;0&gt; &gt; { </p> <blockquote> <p> typedef R type; </p> </blockquote> <p> }; </p> </blockquote> <blockquote> <p> template &lt;class R&gt; struct ratio_subtract&lt;R, ratio&lt;0&gt;&gt; { </p> <blockquote> <p> typedef R type; </p> </blockquote> <p> }; </p> </blockquote> <p> to the file boost/ratio/detail/overflow_helpers.hpp. </p> <p> Sorry for the late replay. Thanks for catching this. </p> <p> I have committed this and two test on trunk: Committed revision 73918. Committed revision 73919. </p> </description> <category>Ticket</category> </item> <item> <author>iorate <iorate_stage@…></author> <pubDate>Sat, 20 Aug 2011 11:12:59 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5724#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5724#comment:5</guid> <description> <p> The solution doesn't work with ratio&lt;0, 2&gt; and so on, I think. The following is better: </p> <pre class="wiki">template &lt;class R, boost::intmax_t D&gt; struct ratio_add&lt;R, ratio&lt;0, D&gt; &gt; { typedef R type; }; template &lt;class R, boost::intmax_t D&gt; struct ratio_subtract&lt;R, ratio&lt;0, D&gt; &gt; { typedef R type; }; </pre> </description> <category>Ticket</category> </item> <item> <author>iorate <iorate_stage@…></author> <pubDate>Sun, 02 Oct 2011 19:45:09 GMT</pubDate> <title>status changed; resolution deleted https://svn.boost.org/trac10/ticket/5724#comment:6 https://svn.boost.org/trac10/ticket/5724#comment:6 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> </ul> Ticket viboes Tue, 01 Nov 2011 20:56:38 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/5724#comment:7 https://svn.boost.org/trac10/ticket/5724#comment:7 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Hi, to late replying to your comments :( </p> <p> I will try to put this in the release, bit it would be easier if you can post the issue on the ML. </p> <p> Fixed in trunk </p> <p> Committed revision 75240. </p> Ticket