Opened 11 years ago

Closed 9 years ago

#5855 closed Bugs (fixed)

narrowing conversion error with -std=c++0x in operator< with int_type != int

Reported by: mlang@… Owned by: Jonathan Turkanis
Milestone: To Be Determined Component: rational
Version: Boost Development Trunk Severity: Problem
Keywords: Cc:

Description

With GCC (4.6) and -std=c++0x, there are several narrowing conversion errors in operator< if int_type is different from int, for example, short int. Example: #include <boost/rational.hpp> int main() { return boost::rational<short int>() < boost::rational<short int>(); } Error output: /tmp/boost/boost/rational.hpp: In member function ‘bool boost::rational<IntType>::operator<(const boost::rational<IntType>&) const [with IntType = short int]’: /tmp/boost/boost/rational.hpp:393:39: error: narrowing conversion of ‘(((int)((const boost::rational<short int>*)this)->boost::rational<short int>::num) / ((int)((const boost::rational<short int>*)this)->boost::rational<short int>::den))’ from ‘int’ to ‘boost::rational<short int>::int_type {aka short int}’ inside { } [-fpermissive] /tmp/boost/boost/rational.hpp:393:39: error: narrowing conversion of ‘(((int)((const boost::rational<short int>*)this)->boost::rational<short int>::num) % ((int)((const boost::rational<short int>*)this)->boost::rational<short int>::den))’ from ‘int’ to ‘boost::rational<short int>::int_type {aka short int}’ inside { } [-fpermissive] ...

Attachments (2)

t.cpp (117 bytes ) - added by mlang@… 11 years ago.
Test case. Compile with gcc -std=c++0x to trigger
rational_fix.patch (879 bytes ) - added by mlang@… 11 years ago.
Proposed fix.

Download all attachments as: .zip

Change History (3)

by mlang@…, 11 years ago

Attachment: t.cpp added

Test case. Compile with gcc -std=c++0x to trigger

by mlang@…, 11 years ago

Attachment: rational_fix.patch added

Proposed fix.

comment:1 by Daryle Walker, 9 years ago

Resolution: fixed
Status: newclosed

(In [85418]) Used static_cast to suppress a warning/error about a narrowing conversion. Fixes #5855.

Note: See TracTickets for help on using tickets.