[Bug c++/92675] sign-conversion C++ unsigned int j = -1;

2024-06-24 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92675

Andrew Pinski  changed:

   What|Removed |Added

 CC||michael.kenzel at gmail dot com

--- Comment #7 from Andrew Pinski  ---
*** Bug 115626 has been marked as a duplicate of this bug. ***

[Bug c++/92675] sign-conversion C++ unsigned int j = -1;

2019-11-28 Thread jg at jguk dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92675

--- Comment #6 from Jonny Grant  ---
Is the clearest way to write this as follows?
unsigned int j = (unsigned int)-1;

Likewise for the template example:

  U max = (U)-1;   // good

[Bug c++/92675] sign-conversion C++ unsigned int j = -1;

2019-11-27 Thread jg at jguk dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92675

--- Comment #5 from Jonny Grant  ---
I tried godbolt trunk again for C++ today with  -Wsign-conversion and it does
give a warning. I can only think I made a mistake while checking - unless a
patch has just gone in?

[Bug c++/92675] sign-conversion C++ unsigned int j = -1;

2019-11-27 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92675

--- Comment #4 from Jonathan Wakely  ---
(In reply to Richard Biener from comment #3)
> -1u also works

Not in a template:

#include 

template
constexpr std::enable_if_t::value, bool>
is_max(U u)
{
#ifdef GOOD
  U max = -1;   // good
#else
  U max = -1u;  // bad
#endif
  return u == max;
}

static_assert(is_max(-1ull));

This fails when GOOD isn't defined, because -1u is UINT_MAX not the maximum
value for the type.

You can use std::numeric_limits::max() or U(-1) but -1 is a convenient
shorthand that does the right thing.

[Bug c++/92675] sign-conversion C++ unsigned int j = -1;

2019-11-26 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92675

Richard Biener  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2019-11-27
 Ever confirmed|0   |1

--- Comment #3 from Richard Biener  ---
-1u also works

[Bug c++/92675] sign-conversion C++ unsigned int j = -1;

2019-11-26 Thread jg at jguk dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92675

--- Comment #2 from Jonny Grant  ---
(In reply to Jonathan Wakely from comment #1)
> That's an idiomatic way to get the largest unsigned value, it would be a
> shame if it warned.

Personally I would use UINT_MAX from limits.h, feels more idiomatic.

[Bug c++/92675] sign-conversion C++ unsigned int j = -1;

2019-11-26 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92675

Jonathan Wakely  changed:

   What|Removed |Added

   Keywords||diagnostic
   Severity|normal  |enhancement

--- Comment #1 from Jonathan Wakely  ---
That's an idiomatic way to get the largest unsigned value, it would be a shame
if it warned.