public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/55671] New: -Wconversion fails to warn for sign-conversion
@ 2012-12-13 8:46 loose at astron dot nl
2012-12-13 10:34 ` [Bug c++/55671] " paolo.carlini at oracle dot com
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: loose at astron dot nl @ 2012-12-13 8:46 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55671
Bug #: 55671
Summary: -Wconversion fails to warn for sign-conversion
Classification: Unclassified
Product: gcc
Version: 4.7.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: loose@astron.nl
g++ doesn't warn about the following statement when using -Wconversion, whereas
gcc does.
$ cat Wconversion-bug.c
unsigned i = -1;
$ g++ -Wconversion -c Wconversion-bug.c
[no output]
$ gcc -Wconversion -c Wconversion-bug.c
Wconversion-bug.c:1:1: warning: negative integer implicitly converted to
unsigned type [-Wsign-conversion]
$ g++ --version
g++ (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/55671] -Wconversion fails to warn for sign-conversion
2012-12-13 8:46 [Bug c++/55671] New: -Wconversion fails to warn for sign-conversion loose at astron dot nl
@ 2012-12-13 10:34 ` paolo.carlini at oracle dot com
2012-12-13 10:36 ` redi at gcc dot gnu.org
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-12-13 10:34 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55671
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |manu at gcc dot gnu.org
--- Comment #1 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-12-13 10:33:48 UTC ---
Looks like, if we want this is trivial to change:
Wsign-conversion
C ObjC C++ ObjC++ Var(warn_sign_conversion) LangEnabledBy(C ObjC,Wconversion)
Warn for implicit type conversions between signed and unsigned integers
Manuel, can you look into this?
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/55671] -Wconversion fails to warn for sign-conversion
2012-12-13 8:46 [Bug c++/55671] New: -Wconversion fails to warn for sign-conversion loose at astron dot nl
2012-12-13 10:34 ` [Bug c++/55671] " paolo.carlini at oracle dot com
@ 2012-12-13 10:36 ` redi at gcc dot gnu.org
2012-12-13 10:38 ` redi at gcc dot gnu.org
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2012-12-13 10:36 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55671
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-12-13 10:35:58 UTC ---
Surely this is by design, as documented:
Warnings about conversions between signed and unsigned integers are
disabled by default in C++ unless -Wsign-conversion is explicitly enabled.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/55671] -Wconversion fails to warn for sign-conversion
2012-12-13 8:46 [Bug c++/55671] New: -Wconversion fails to warn for sign-conversion loose at astron dot nl
2012-12-13 10:34 ` [Bug c++/55671] " paolo.carlini at oracle dot com
2012-12-13 10:36 ` redi at gcc dot gnu.org
@ 2012-12-13 10:38 ` redi at gcc dot gnu.org
2012-12-13 10:42 ` paolo.carlini at oracle dot com
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2012-12-13 10:38 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55671
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-12-13 10:37:34 UTC ---
This is a common idiom in C++ and shouldn't warn e.g.
static const size_type npos = -1;
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/55671] -Wconversion fails to warn for sign-conversion
2012-12-13 8:46 [Bug c++/55671] New: -Wconversion fails to warn for sign-conversion loose at astron dot nl
` (2 preceding siblings ...)
2012-12-13 10:38 ` redi at gcc dot gnu.org
@ 2012-12-13 10:42 ` paolo.carlini at oracle dot com
2012-12-13 11:10 ` loose at astron dot nl
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-12-13 10:42 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55671
--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-12-13 10:41:49 UTC ---
I agree, I suspected it was by the design. Since Manuel worked on this, let's
wait a bit before closing the Bug.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/55671] -Wconversion fails to warn for sign-conversion
2012-12-13 8:46 [Bug c++/55671] New: -Wconversion fails to warn for sign-conversion loose at astron dot nl
` (3 preceding siblings ...)
2012-12-13 10:42 ` paolo.carlini at oracle dot com
@ 2012-12-13 11:10 ` loose at astron dot nl
2012-12-13 11:26 ` redi at gcc dot gnu.org
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: loose at astron dot nl @ 2012-12-13 11:10 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55671
--- Comment #5 from loose at astron dot nl 2012-12-13 11:09:43 UTC ---
If this is by design, then the documentation is buggy. Here's a literal quote
form the man page of g++
-Wconversion
Warn for implicit conversions that may alter a value. This includes
conversions between real and integer, like "abs (x)" when "x" is
"double"; conversions between signed and unsigned, like "unsigned
ui = -1"; and conversions to smaller types, like "sqrtf (M_PI)". Do
not warn for explicit casts like "abs ((int) x)" and "ui =
(unsigned) -1", or if the value is not changed by the conversion
like in "abs (2.0)". Warnings about conversions between signed and
unsigned integers can be disabled by using -Wno-sign-conversion.
For C++, also warn for confusing overload resolution for user-
defined conversions; and conversions that will never use a type
conversion operator: conversions to "void", the same type, a base
class or a reference to them. Warnings about conversions between
signed and unsigned integers are disabled by default in C++ unless
-Wsign-conversion is explicitly enabled.
It explicitly gives the example "unsigned ui = -1" as an example.
Furthermore, older g++ compilers used to give this warning. I tried it with g++
4.1.2 and it properly gives a warning.
I also find it a bit counter-intuitive that gcc *does* warn about it, whereas
g++ does *not*.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/55671] -Wconversion fails to warn for sign-conversion
2012-12-13 8:46 [Bug c++/55671] New: -Wconversion fails to warn for sign-conversion loose at astron dot nl
` (4 preceding siblings ...)
2012-12-13 11:10 ` loose at astron dot nl
@ 2012-12-13 11:26 ` redi at gcc dot gnu.org
2012-12-13 11:29 ` paolo.carlini at oracle dot com
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2012-12-13 11:26 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55671
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-12-13 11:25:37 UTC ---
It gives it as an example then says "Warnings about conversions between signed
and unsigned integers are disabled by default in C++ unless -Wsign-conversion
is explicitly enabled."
You only have to read the next paragraph.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/55671] -Wconversion fails to warn for sign-conversion
2012-12-13 8:46 [Bug c++/55671] New: -Wconversion fails to warn for sign-conversion loose at astron dot nl
` (5 preceding siblings ...)
2012-12-13 11:26 ` redi at gcc dot gnu.org
@ 2012-12-13 11:29 ` paolo.carlini at oracle dot com
2012-12-13 12:03 ` loose at astron dot nl
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-12-13 11:29 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55671
--- Comment #7 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-12-13 11:29:24 UTC ---
This is definitely by design, as the snippet I posted also clearly shows. The
documentation could be maybe improved I agree, but it's a very general issue
that it often gives more space to C than C++ because the latter is more recent
in the development history of GCC. Maybe in this case we could repeat the
example at the end and emphasize that we do *not* warn in C++ because it's
indeed a common idiom in C++. Hey, C and C++ are two different languages,
remember, and many details in the Standards are different also in basic (eg, no
classes, no templates) areas.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/55671] -Wconversion fails to warn for sign-conversion
2012-12-13 8:46 [Bug c++/55671] New: -Wconversion fails to warn for sign-conversion loose at astron dot nl
` (6 preceding siblings ...)
2012-12-13 11:29 ` paolo.carlini at oracle dot com
@ 2012-12-13 12:03 ` loose at astron dot nl
2012-12-13 13:25 ` manu at gcc dot gnu.org
2012-12-13 23:30 ` paolo.carlini at oracle dot com
9 siblings, 0 replies; 11+ messages in thread
From: loose at astron dot nl @ 2012-12-13 12:03 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55671
--- Comment #8 from loose at astron dot nl 2012-12-13 12:03:02 UTC ---
OK, fine with me. It's only that I was caught by surprise that g++ did no
longer warn about sign conversion. I can definitely live with an explicit
-Wsign-conversion, though.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/55671] -Wconversion fails to warn for sign-conversion
2012-12-13 8:46 [Bug c++/55671] New: -Wconversion fails to warn for sign-conversion loose at astron dot nl
` (7 preceding siblings ...)
2012-12-13 12:03 ` loose at astron dot nl
@ 2012-12-13 13:25 ` manu at gcc dot gnu.org
2012-12-13 23:30 ` paolo.carlini at oracle dot com
9 siblings, 0 replies; 11+ messages in thread
From: manu at gcc dot gnu.org @ 2012-12-13 13:25 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55671
--- Comment #9 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2012-12-13 13:24:51 UTC ---
Wsign-conversion was disabled for g++ by explicit request. I don't remember the
details and Google seems unable to find the relevant discussion in gcc-patches.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/55671] -Wconversion fails to warn for sign-conversion
2012-12-13 8:46 [Bug c++/55671] New: -Wconversion fails to warn for sign-conversion loose at astron dot nl
` (8 preceding siblings ...)
2012-12-13 13:25 ` manu at gcc dot gnu.org
@ 2012-12-13 23:30 ` paolo.carlini at oracle dot com
9 siblings, 0 replies; 11+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-12-13 23:30 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55671
Paolo Carlini <paolo.carlini at oracle dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |WORKSFORME
--- Comment #10 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-12-13 23:29:42 UTC ---
Guess we can close this.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2012-12-13 23:30 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-13 8:46 [Bug c++/55671] New: -Wconversion fails to warn for sign-conversion loose at astron dot nl
2012-12-13 10:34 ` [Bug c++/55671] " paolo.carlini at oracle dot com
2012-12-13 10:36 ` redi at gcc dot gnu.org
2012-12-13 10:38 ` redi at gcc dot gnu.org
2012-12-13 10:42 ` paolo.carlini at oracle dot com
2012-12-13 11:10 ` loose at astron dot nl
2012-12-13 11:26 ` redi at gcc dot gnu.org
2012-12-13 11:29 ` paolo.carlini at oracle dot com
2012-12-13 12:03 ` loose at astron dot nl
2012-12-13 13:25 ` manu at gcc dot gnu.org
2012-12-13 23:30 ` 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).