public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101649] New: -Wdouble-promotion warning emitted when floating point literals are not actually promoted to doubles
@ 2021-07-27 18:38 make_all@t-online.de
  2021-07-27 18:42 ` [Bug c++/101649] " mpolacek at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: make_all@t-online.de @ 2021-07-27 18:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101649

            Bug ID: 101649
           Summary: -Wdouble-promotion warning emitted when floating point
                    literals are not actually promoted to doubles
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: make_all@t-online.de
  Target Milestone: ---

GCC emits a double promotion warning when using the literal 0.5 with a float.
For example

float func(float num) {
    return num * 0.5;
}

warning: implicit conversion from 'float' to 'double' to match other operand of
binary expression [-Wdouble-promotion]
    3 |     return num * 0.5;

However, GCC does not actually use the double representation for this literal
(and others than can be represented equally in float as in double).
The assembler output for both "0.5" and "0.5f" is the same:

func(float):
        push    rbp
        mov     rbp, rsp
        movss   DWORD PTR [rbp-4], xmm0
        movss   xmm1, DWORD PTR [rbp-4]
        movss   xmm0, DWORD PTR .LC0[rip]
        mulss   xmm0, xmm1
        pop     rbp
        ret
.LC0:
        .long   1056964608

This warning is misleading and should not be emitted

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

end of thread, other threads:[~2021-08-02 17:21 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-27 18:38 [Bug c++/101649] New: -Wdouble-promotion warning emitted when floating point literals are not actually promoted to doubles make_all@t-online.de
2021-07-27 18:42 ` [Bug c++/101649] " mpolacek at gcc dot gnu.org
2021-07-27 19:18 ` make_all@t-online.de
2021-07-27 19:29 ` pinskia at gcc dot gnu.org
2021-07-27 19:54 ` make_all@t-online.de
2021-07-28  6:33 ` rguenth at gcc dot gnu.org
2021-08-02 17:03 ` make_all@t-online.de
2021-08-02 17:21 ` make_all@t-online.de

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).