Modify

Opened 6 years ago

Closed 4 years ago

#5855 closed Bugs (fixed)

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

Reported by: mlang@… Owned by: 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@… 6 years ago.
Test case. Compile with gcc -std=c++0x to trigger
rational_fix.patch (879 bytes) - added by mlang@… 6 years ago.
Proposed fix.

Download all attachments as: .zip

Change History (3)

Changed 6 years ago by mlang@…

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

Changed 6 years ago by mlang@…

Proposed fix.

comment:1 Changed 4 years ago by dlwalker

  • Resolution set to fixed
  • Status changed from new to closed

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

Add Comment

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain turkanis.
The resolution will be deleted. Next status will be 'reopened'.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.