public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107388] New: GCC should diagnose unsigned to signed conversion with -Wconversion
@ 2022-10-24 23:17 nikolasklauser at berlin dot de
2022-10-24 23:20 ` [Bug c++/107388] " mpolacek at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: nikolasklauser at berlin dot de @ 2022-10-24 23:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107388
Bug ID: 107388
Summary: GCC should diagnose unsigned to signed conversion
with -Wconversion
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: nikolasklauser at berlin dot de
Target Milestone: ---
It looks like GCC currently doesn't diagnose a conversion from unsigned int to
int, but as I understand it -Wconversion should diagnose any conversion that
might change the value.
Here is an example: (Godbolt: https://godbolt.org/z/Mr8KvTW66)
#include <cstddef>
#include <cstdlib>
void func(unsigned int size) {
[[maybe_unused]] int v = size; // doesn't get diagnosed
}
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/107388] GCC should diagnose unsigned to signed conversion with -Wconversion
2022-10-24 23:17 [Bug c++/107388] New: GCC should diagnose unsigned to signed conversion with -Wconversion nikolasklauser at berlin dot de
@ 2022-10-24 23:20 ` mpolacek at gcc dot gnu.org
2022-10-24 23:20 ` mpolacek at gcc dot gnu.org
2022-10-25 19:57 ` nikolasklauser at berlin dot de
2 siblings, 0 replies; 4+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-10-24 23:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107388
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
CC| |mpolacek at gcc dot gnu.org
--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
This is -Wsign-conversion:
$ ./cc1plus -quiet t.C -Wsign-conversion
t.C: In function ‘void func(unsigned int)’:
t.C:2:28: warning: conversion to ‘int’ from ‘unsigned int’ may change the sign
of the result [-Wsign-conversion]
2 | [[maybe_unused]] int v = size; // doesn't get diagnosed
| ^~~~
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/107388] GCC should diagnose unsigned to signed conversion with -Wconversion
2022-10-24 23:17 [Bug c++/107388] New: GCC should diagnose unsigned to signed conversion with -Wconversion nikolasklauser at berlin dot de
2022-10-24 23:20 ` [Bug c++/107388] " mpolacek at gcc dot gnu.org
@ 2022-10-24 23:20 ` mpolacek at gcc dot gnu.org
2022-10-25 19:57 ` nikolasklauser at berlin dot de
2 siblings, 0 replies; 4+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-10-24 23:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107388
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|INVALID |WORKSFORME
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/107388] GCC should diagnose unsigned to signed conversion with -Wconversion
2022-10-24 23:17 [Bug c++/107388] New: GCC should diagnose unsigned to signed conversion with -Wconversion nikolasklauser at berlin dot de
2022-10-24 23:20 ` [Bug c++/107388] " mpolacek at gcc dot gnu.org
2022-10-24 23:20 ` mpolacek at gcc dot gnu.org
@ 2022-10-25 19:57 ` nikolasklauser at berlin dot de
2 siblings, 0 replies; 4+ messages in thread
From: nikolasklauser at berlin dot de @ 2022-10-25 19:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107388
--- Comment #2 from Nikolas Klauser <nikolasklauser at berlin dot de> ---
Shouldn't -Wconversion also enable -Wsign-conversion? -Wconversion sounds to me
like it should diagnose all conversions, especially since it's the same kind of
bug I want to catch by enabling the flags. In which case would I be interested
in different sizes but not different signs?
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-10-25 19:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-24 23:17 [Bug c++/107388] New: GCC should diagnose unsigned to signed conversion with -Wconversion nikolasklauser at berlin dot de
2022-10-24 23:20 ` [Bug c++/107388] " mpolacek at gcc dot gnu.org
2022-10-24 23:20 ` mpolacek at gcc dot gnu.org
2022-10-25 19:57 ` nikolasklauser at berlin dot 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).