Modify

Ticket #5855 (closed Bugs: fixed)

Opened 3 years ago

Last modified 8 months ago

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

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

Change History

Changed 3 years ago by mlang@…

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

Changed 3 years ago by mlang@…

Proposed fix.

comment:1 Changed 8 months ago by dlwalker

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

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

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
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.