Opened 11 years ago
Closed 11 years ago
#5724 closed Bugs (fixed)
"0 + 0" and "0 - 0" lead to a compile time error
Reported by: | Owned by: | viboes | |
---|---|---|---|
Milestone: | To Be Determined | Component: | ratio |
Version: | Boost 1.47.0 | Severity: | Problem |
Keywords: | Cc: |
Description
The following code causes a compilication error under GCC 4.5, 4.6 and VC 10.
#define BOOST_RATIO_EXTENSIONS #include <boost/ratio.hpp> using namespace boost; typedef ratio_add<ratio<0>, ratio<0> >::type zero_plus_zero; typedef ratio_subtract<ratio<0>, ratio<0> >::type zero_minus_zero;
Error messages (GCC 4.6.0):
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<boost::ratio<0ll>, boost::ratio<0ll> >': C:/Opt/boost/boost/ratio/ratio.hpp:136:8: instantiated from 'boost::ratio_add<boost::ratio<0ll>, boost::ratio<0ll> >' 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<boost::ratio<0ll>, boost::ratio<0ll> >' 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<boost::ratio<0ll>, boost::ratio<0ll> >': C:/Opt/boost/boost/ratio/ratio.hpp:142:8: instantiated from 'boost::ratio_subtract<boost::ratio<0ll>, boost::ratio<0ll> >' 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<boost::ratio<0ll>, boost::ratio<0ll> >' does not name a type
Change History (7)
comment:1 by , 11 years ago
Component: | None → ratio |
---|---|
Owner: | set to |
comment:2 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:3 by , 11 years ago
comment:4 by , 11 years ago
I have added two partial specialization that solve the issue.
template <class R> struct ratio_add<R, ratio<0> > {
typedef R type;
};
template <class R> struct ratio_subtract<R, ratio<0>> {
typedef R type;
};
to the file boost/ratio/detail/overflow_helpers.hpp.
Sorry for the late replay. Thanks for catching this.
I have committed this and two test on trunk: Committed revision 73918. Committed revision 73919.
comment:5 by , 11 years ago
The solution doesn't work with ratio<0, 2> and so on, I think. The following is better:
template <class R, boost::intmax_t D> struct ratio_add<R, ratio<0, D> > { typedef R type; }; template <class R, boost::intmax_t D> struct ratio_subtract<R, ratio<0, D> > { typedef R type; };
comment:6 by , 11 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
comment:7 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
Hi, to late replying to your comments :(
I will try to put this in the release, bit it would be easier if you can post the issue on the ML.
Fixed in trunk
Committed revision 75240.
(In [73918]) ratio: fix #5724: 0 + 0 and 0 - 0 lead to a compile time error