public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/55077] New: implement and enable by default -Wliteral-conversion
@ 2012-10-25 23:52 manu at gcc dot gnu.org
  2012-10-27 19:48 ` [Bug c++/55077] " manu at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: manu at gcc dot gnu.org @ 2012-10-25 23:52 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 55077
           Summary: implement and enable by default -Wliteral-conversion
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: manu@gcc.gnu.org


>From clang:

test.cc:4:23: warning: implicit conversion from 'double' to 'int' changes value
from 3.1415926 to 3 [-Wliteral-conversion]
 static const int c = 3.1415926;
                  ~   ^~~~~~~~~

This should be fairly easy, since we warn already with -Wconversion:

1) Change the warning flag.
2) Show the values before/after.


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

* [Bug c++/55077] implement and enable by default -Wliteral-conversion
  2012-10-25 23:52 [Bug c++/55077] New: implement and enable by default -Wliteral-conversion manu at gcc dot gnu.org
@ 2012-10-27 19:48 ` manu at gcc dot gnu.org
  2012-10-28 18:02 ` joseph at codesourcery dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: manu at gcc dot gnu.org @ 2012-10-27 19:48 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #1 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-10-27 19:48:25 UTC ---
Problem: We do not want to warn for expressions. From the clang testcases:

  // Expressions, such as those that indicate rounding-down, should NOT produce
warnings.
  int x = 24 * 0.5;
  int y = (24*60*60) * 0.25;
  int pennies = 123.45 * 100;

But gcc folds those before conversion_warning, so we cannot know they are
expressions... :-(


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

* [Bug c++/55077] implement and enable by default -Wliteral-conversion
  2012-10-25 23:52 [Bug c++/55077] New: implement and enable by default -Wliteral-conversion manu at gcc dot gnu.org
  2012-10-27 19:48 ` [Bug c++/55077] " manu at gcc dot gnu.org
@ 2012-10-28 18:02 ` joseph at codesourcery dot com
  2013-11-10  6:37 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: joseph at codesourcery dot com @ 2012-10-28 18:02 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #2 from joseph at codesourcery dot com <joseph at codesourcery dot com> 2012-10-28 18:02:07 UTC ---
On Sat, 27 Oct 2012, manu at gcc dot gnu.org wrote:

>   // Expressions, such as those that indicate rounding-down, should NOT produce
> warnings.
>   int x = 24 * 0.5;
>   int y = (24*60*60) * 0.25;
>   int pennies = 123.45 * 100;

The last of those seems pretty suspicious (123.45 isn't an exact 
floating-point value, but the user probably wants 12345 independent of 
whether the floating-point value is above or below the exact decimal 
value).  Are you *sure* you don't want a warning in such a case?


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

* [Bug c++/55077] implement and enable by default -Wliteral-conversion
  2012-10-25 23:52 [Bug c++/55077] New: implement and enable by default -Wliteral-conversion manu at gcc dot gnu.org
  2012-10-27 19:48 ` [Bug c++/55077] " manu at gcc dot gnu.org
  2012-10-28 18:02 ` joseph at codesourcery dot com
@ 2013-11-10  6:37 ` pinskia at gcc dot gnu.org
  2022-04-14 15:55 ` dcb314 at hotmail dot com
  2023-05-31  2:16 ` egallager at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2013-11-10  6:37 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-11-10
     Ever confirmed|0                           |1

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.


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

* [Bug c++/55077] implement and enable by default -Wliteral-conversion
  2012-10-25 23:52 [Bug c++/55077] New: implement and enable by default -Wliteral-conversion manu at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2013-11-10  6:37 ` pinskia at gcc dot gnu.org
@ 2022-04-14 15:55 ` dcb314 at hotmail dot com
  2023-05-31  2:16 ` egallager at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: dcb314 at hotmail dot com @ 2022-04-14 15:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from David Binderman <dcb314 at hotmail dot com> ---
-Wfloat-conversion does the deed: any chance of getting it someplace useful
like -Wall or -Wextra anytime soon ?

I will put it into my local compiler.

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

* [Bug c++/55077] implement and enable by default -Wliteral-conversion
  2012-10-25 23:52 [Bug c++/55077] New: implement and enable by default -Wliteral-conversion manu at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2022-04-14 15:55 ` dcb314 at hotmail dot com
@ 2023-05-31  2:16 ` egallager at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: egallager at gcc dot gnu.org @ 2023-05-31  2:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to David Binderman from comment #9)
> -Wfloat-conversion does the deed: any chance of getting it someplace useful
> like -Wall or -Wextra anytime soon ?
> 
> I will put it into my local compiler.

I think the point here is that the proposed -Wliteral-conversion warns for a
smaller number of cases than -Wfloat-conversion does, and thus would be safer
to enable more widely than -Wfloat-conversion is.

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

end of thread, other threads:[~2023-05-31  2:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-25 23:52 [Bug c++/55077] New: implement and enable by default -Wliteral-conversion manu at gcc dot gnu.org
2012-10-27 19:48 ` [Bug c++/55077] " manu at gcc dot gnu.org
2012-10-28 18:02 ` joseph at codesourcery dot com
2013-11-10  6:37 ` pinskia at gcc dot gnu.org
2022-04-14 15:55 ` dcb314 at hotmail dot com
2023-05-31  2:16 ` egallager at gcc dot gnu.org

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