public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/56292] New: False positive for constexpr arithmetics (-Wconversion)
@ 2013-02-12  8:07 lcid-fire at gmx dot net
  2013-02-12  9:04 ` [Bug c++/56292] " jakub at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: lcid-fire at gmx dot net @ 2013-02-12  8:07 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 56292
           Summary: False positive for constexpr arithmetics
                    (-Wconversion)
    Classification: Unclassified
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: lcid-fire@gmx.net


For the following code one gets 'conversion' diagnostics, while the compiler
should be able to compute, that it is actually fine.

#include <cstdint>
constexpr std::uint8_t func() { return 2; }
std::uint8_t value = func() + 2;

Results in:
warning: conversion to ‘uint8_t {aka unsigned char}’ from ‘int’ may alter its
value [-Wconversion]

Diagnostics works fine if you replace 'func()' with a number.


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

* [Bug c++/56292] False positive for constexpr arithmetics (-Wconversion)
  2013-02-12  8:07 [Bug c++/56292] New: False positive for constexpr arithmetics (-Wconversion) lcid-fire at gmx dot net
@ 2013-02-12  9:04 ` jakub at gcc dot gnu.org
  2013-02-12 10:13 ` lcid-fire at gmx dot net
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-02-12  9:04 UTC (permalink / raw)
  To: gcc-bugs


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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-02-12 09:03:44 UTC ---
func() + 2 is evaluated as (unsigned char) (((int) func ()) + 2), so when the
-Wconversion warning is diagnosed before evaluating all the constexpr
expressions into constants if possible, the warning is reasonable.
Consider
constexpr std::uint8_t func() { return 0xff; }
std::uint8_t value = func() + 2;


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

* [Bug c++/56292] False positive for constexpr arithmetics (-Wconversion)
  2013-02-12  8:07 [Bug c++/56292] New: False positive for constexpr arithmetics (-Wconversion) lcid-fire at gmx dot net
  2013-02-12  9:04 ` [Bug c++/56292] " jakub at gcc dot gnu.org
@ 2013-02-12 10:13 ` lcid-fire at gmx dot net
  2013-02-12 12:29 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: lcid-fire at gmx dot net @ 2013-02-12 10:13 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #2 from lcid-fire at gmx dot net 2013-02-12 10:13:17 UTC ---
But should it be evaluated before constexpr are processed?


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

* [Bug c++/56292] False positive for constexpr arithmetics (-Wconversion)
  2013-02-12  8:07 [Bug c++/56292] New: False positive for constexpr arithmetics (-Wconversion) lcid-fire at gmx dot net
  2013-02-12  9:04 ` [Bug c++/56292] " jakub at gcc dot gnu.org
  2013-02-12 10:13 ` lcid-fire at gmx dot net
@ 2013-02-12 12:29 ` rguenth at gcc dot gnu.org
  2013-02-12 15:24 ` lcid-fire at gmx dot net
  2014-11-18 13:44 ` paolo.carlini at oracle dot com
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-02-12 12:29 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> 2013-02-12 12:29:28 UTC ---
Does it also warn if you make value a constexpr?


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

* [Bug c++/56292] False positive for constexpr arithmetics (-Wconversion)
  2013-02-12  8:07 [Bug c++/56292] New: False positive for constexpr arithmetics (-Wconversion) lcid-fire at gmx dot net
                   ` (2 preceding siblings ...)
  2013-02-12 12:29 ` rguenth at gcc dot gnu.org
@ 2013-02-12 15:24 ` lcid-fire at gmx dot net
  2014-11-18 13:44 ` paolo.carlini at oracle dot com
  4 siblings, 0 replies; 6+ messages in thread
From: lcid-fire at gmx dot net @ 2013-02-12 15:24 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #4 from lcid-fire at gmx dot net 2013-02-12 15:23:58 UTC ---
constexpr std::uint8_t value = func() + 2;

does generate the same warning.


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

* [Bug c++/56292] False positive for constexpr arithmetics (-Wconversion)
  2013-02-12  8:07 [Bug c++/56292] New: False positive for constexpr arithmetics (-Wconversion) lcid-fire at gmx dot net
                   ` (3 preceding siblings ...)
  2013-02-12 15:24 ` lcid-fire at gmx dot net
@ 2014-11-18 13:44 ` paolo.carlini at oracle dot com
  4 siblings, 0 replies; 6+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-11-18 13:44 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
      Known to work|                            |4.9.0, 4.9.1, 5.0
         Resolution|---                         |FIXED
   Target Milestone|---                         |4.9.0

--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> ---
This is fixed in 4.9.0.


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

end of thread, other threads:[~2014-11-18 13:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-12  8:07 [Bug c++/56292] New: False positive for constexpr arithmetics (-Wconversion) lcid-fire at gmx dot net
2013-02-12  9:04 ` [Bug c++/56292] " jakub at gcc dot gnu.org
2013-02-12 10:13 ` lcid-fire at gmx dot net
2013-02-12 12:29 ` rguenth at gcc dot gnu.org
2013-02-12 15:24 ` lcid-fire at gmx dot net
2014-11-18 13:44 ` paolo.carlini at oracle 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).