Opened 9 years ago

Last modified 9 years ago

#9239 new Bugs

Implicit type conversion without warning, although Wconversion used

Reported by: Daniel Rings <topwohnung@…> Owned by: Matthias Schabel
Milestone: To Be Determined Component: units
Version: Boost 1.54.0 Severity: Problem
Keywords: units auto Cc:

Description

When defining a variable with automatic type recognition,

auto inv_time = 1/si::second;

this instruction

inv_time = 0.4/si::second;

does not generate a warning (using -Wconversion), while

auto p = 3;
p = 1.0/2.0;

generates a warning, as it should. Is there any reason for the different behavior in both cases? It should be mentioned that this is not contingent to "auto", for

quantity<si::time,int>  time = 1/(1/si::second);
time = 0.4*si::second;

compiles without warning, too (and time = 0 s in the end). I thought implicit typecasts with possible loss of precision were forbidden or would at least trigger a warning.

Change History (1)

comment:1 by Steven Watanabe, 9 years ago

It's not really possible to emulate the behavior of built in types in this regard. If it did generate a warning it would be impossible to suppress with a cast.

Note: See TracTickets for help on using tickets.