public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/41779]  New: Spurious integral promotion
@ 2009-10-21  9:16 zweije at xs4all dot nl
  2009-12-29 18:02 ` [Bug c++/41779] " foo at mailinator dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: zweije at xs4all dot nl @ 2009-10-21  9:16 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1476 bytes --]

The following code produces a warning about precision loss in an int-to-float
conversion:

    $cat warn.cpp
    float f(float x, unsigned short y)
    {
        return x * y;
    }
    $g++ -Wconversion -c -o warn.o warn.cpp
    warn.cpp: In function ‘float f(float, short unsigned int)’:
    warn.cpp:3: warning: conversion to ‘float’ from ‘int’ may alter its value
    $

The code snippet does not have an int-to-float conversion.

It does have an unsigned short-to-float conversion according to the C++
standard, chapter 5 [expr] para 9: "[inapplicable note on long double and
double...] Otherwise, if either operand is float, the other shall be converted
to float [...]". Only after this rule, integral promotions are performed, which
could promote the unsigned short to an int.

Moreover, he conversion does not lose information since the 16 bits of the
unsigned short fit amply in the float's mantissa.

Not tested with other shorter-than-int types. This problem might apply there as
well...


-- 
           Summary: Spurious integral promotion
           Product: gcc
           Version: 4.4.1
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: zweije at xs4all dot nl
 GCC build triplet: x86_64-linux-gnu
  GCC host triplet: x86_64-linux-gnu
GCC target triplet: x86_64-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41779


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-02-23 13:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-21  9:16 [Bug c++/41779] New: Spurious integral promotion zweije at xs4all dot nl
2009-12-29 18:02 ` [Bug c++/41779] " foo at mailinator dot com
2009-12-31 11:02 ` zweije at xs4all dot nl
2010-02-14 20:28 ` [Bug c++/41779] Wconversion cannot see throught real*integer promotions manu at gcc dot gnu dot org
2010-02-19 21:12 ` manu at gcc dot gnu dot org
2010-02-19 21:14 ` manu at gcc dot gnu dot org
2010-02-23 13:59 ` hjl dot tools at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).