[Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752 --- Comment #37 from CVS Commits --- The master branch has been updated by Jason Merrill : https://gcc.gnu.org/g:6d00f052ef209bacdd93f503b0c5fb428cc6c434 commit r10-6181-g6d00f052ef209bacdd93f503b0c5fb428cc6c434 Author: Jason Merrill Date: Thu Jan 23 10:37:18 2020 -0500 c-family: One more 40752 tweak for unsigned char. My last patch didn't fix all the failures on unsignd char targets. We were missing one warning because by suppressing -Wsign-conversion for the second operand of + we missed an overflow that we want to warn about, and we properly don't warn about unsigned / or %. PR testsuite/93391 - PR 40752 test fails with unsigned plain char. * c-warn.c (conversion_warning): Change -Wsign-conversion handling. * lib/target-supports.exp (check_effective_target_unsigned_char): New.
[Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752 --- Comment #36 from CVS Commits --- The master branch has been updated by Jason Merrill : https://gcc.gnu.org/g:55b7df8bfb12938e7716445d4e2dc0d2ddf44bac commit r10-6157-g55b7df8bfb12938e7716445d4e2dc0d2ddf44bac Author: Jason Merrill Date: Wed Jan 22 14:21:06 2020 -0500 c-family: Fix problems with blender and PPC from PR 40752 patch. blender in SPEC is built with -funsigned-char, which is also the default on PPC, and exposed -Wsign-conversion issues that weren't seen by the x86_64 testsuite. In blender we were complaining about operands to an expression that we didn't't previously complain about as a whole. So only check operands after we check the whole expression. Also, to fix the PR 40752 testcases on -funsigned-char targets, don't consider -Wsign-conversion for the second operand of PLUS_EXPR, especially since fold changes "x - 5" to "x + (-5)". And don't use SCHAR_MAX with plain char. PR testsuite/93391 - PR 40752 test fails with unsigned plain char. PR c++/40752 * c-warn.c (conversion_warning): Check operands only after checking the whole expression. Don't check second operand of + for sign.
[Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752 seurer at gcc dot gnu.org changed: What|Removed |Added CC||seurer at gcc dot gnu.org --- Comment #35 from seurer at gcc dot gnu.org --- I see even more failures on powerpc64 both BE and LE: > FAIL: c-c++-common/Wconversion-pr40752.c -Wc++-compat (test for warnings, > line 34) > FAIL: c-c++-common/Wconversion-pr40752.c -Wc++-compat (test for warnings, > line 38) > FAIL: c-c++-common/Wconversion-pr40752.c -Wc++-compat (test for warnings, > line 40) > FAIL: c-c++-common/Wconversion-pr40752.c -Wc++-compat (test for warnings, > line 42) > FAIL: c-c++-common/Wconversion-pr40752.c -Wc++-compat (test for excess > errors) > FAIL: c-c++-common/Wconversion-pr40752.c -std=gnu++14 (test for warnings, > line 34) > FAIL: c-c++-common/Wconversion-pr40752.c -std=gnu++14 (test for warnings, > line 36) > FAIL: c-c++-common/Wconversion-pr40752.c -std=gnu++14 (test for warnings, > line 38) > FAIL: c-c++-common/Wconversion-pr40752.c -std=gnu++14 (test for warnings, > line 40) > FAIL: c-c++-common/Wconversion-pr40752.c -std=gnu++14 (test for warnings, > line 42) > FAIL: c-c++-common/Wconversion-pr40752.c -std=gnu++17 (test for warnings, > line 34) > FAIL: c-c++-common/Wconversion-pr40752.c -std=gnu++17 (test for warnings, > line 36) > FAIL: c-c++-common/Wconversion-pr40752.c -std=gnu++17 (test for warnings, > line 38) > FAIL: c-c++-common/Wconversion-pr40752.c -std=gnu++17 (test for warnings, > line 40) > FAIL: c-c++-common/Wconversion-pr40752.c -std=gnu++17 (test for warnings, > line 42) > FAIL: c-c++-common/Wconversion-pr40752.c -std=gnu++2a (test for warnings, > line 34) > FAIL: c-c++-common/Wconversion-pr40752.c -std=gnu++2a (test for warnings, > line 36) > FAIL: c-c++-common/Wconversion-pr40752.c -std=gnu++2a (test for warnings, > line 38) > FAIL: c-c++-common/Wconversion-pr40752.c -std=gnu++2a (test for warnings, > line 40) > FAIL: c-c++-common/Wconversion-pr40752.c -std=gnu++2a (test for warnings, > line 42) > FAIL: c-c++-common/Wconversion-pr40752.c -std=gnu++98 (test for warnings, > line 34) > FAIL: c-c++-common/Wconversion-pr40752.c -std=gnu++98 (test for warnings, > line 36) > FAIL: c-c++-common/Wconversion-pr40752.c -std=gnu++98 (test for warnings, > line 38) > FAIL: c-c++-common/Wconversion-pr40752.c -std=gnu++98 (test for warnings, > line 40) > FAIL: c-c++-common/Wconversion-pr40752.c -std=gnu++98 (test for warnings, > line 42) > FAIL: c-c++-common/Wconversion-pr40752a.c -Wc++-compat (test for warnings, > line 17) > FAIL: c-c++-common/Wconversion-pr40752a.c -Wc++-compat (test for warnings, > line 19) > FAIL: c-c++-common/Wconversion-pr40752a.c -Wc++-compat (test for warnings, > line 40) > FAIL: c-c++-common/Wconversion-pr40752a.c -Wc++-compat (test for warnings, > line 42) > FAIL: c-c++-common/Wconversion-pr40752a.c -std=gnu++14 (test for warnings, > line 12) > FAIL: c-c++-common/Wconversion-pr40752a.c -std=gnu++14 (test for warnings, > line 17) > FAIL: c-c++-common/Wconversion-pr40752a.c -std=gnu++14 (test for warnings, > line 19) > FAIL: c-c++-common/Wconversion-pr40752a.c -std=gnu++14 (test for warnings, > line 36) > FAIL: c-c++-common/Wconversion-pr40752a.c -std=gnu++17 (test for warnings, > line 12) > FAIL: c-c++-common/Wconversion-pr40752a.c -std=gnu++17 (test for warnings, > line 17) > FAIL: c-c++-common/Wconversion-pr40752a.c -std=gnu++17 (test for warnings, > line 19) > FAIL: c-c++-common/Wconversion-pr40752a.c -std=gnu++17 (test for warnings, > line 36) > FAIL: c-c++-common/Wconversion-pr40752a.c -std=gnu++2a (test for warnings, > line 12) > FAIL: c-c++-common/Wconversion-pr40752a.c -std=gnu++2a (test for warnings, > line 17) > FAIL: c-c++-common/Wconversion-pr40752a.c -std=gnu++2a (test for warnings, > line 19) > FAIL: c-c++-common/Wconversion-pr40752a.c -std=gnu++2a (test for warnings, > line 36) > FAIL: c-c++-common/Wconversion-pr40752a.c -std=gnu++98 (test for warnings, > line 12) > FAIL: c-c++-common/Wconversion-pr40752a.c -std=gnu++98 (test for warnings, > line 17) > FAIL: c-c++-common/Wconversion-pr40752a.c -std=gnu++98 (test for warnings, > line 19) > FAIL: c-c++-common/Wconversion-pr40752a.c -std=gnu++98 (test for warnings, > line 36)
[Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752 Christophe Lyon changed: What|Removed |Added CC||clyon at gcc dot gnu.org --- Comment #34 from Christophe Lyon --- (In reply to Jason Merrill from comment #33) > Fixed for GCC 10. Hi, I've noticed that the new tests fail: c-c++-common/Wconversion-pr40752.c -Wc++-compat (test for warnings, line 34) c-c++-common/Wconversion-pr40752.c -Wc++-compat (test for warnings, line 38) c-c++-common/Wconversion-pr40752.c -Wc++-compat (test for warnings, line 40) c-c++-common/Wconversion-pr40752.c -Wc++-compat (test for warnings, line 42) c-c++-common/Wconversion-pr40752.c -Wc++-compat (test for excess errors) c-c++-common/Wconversion-pr40752a.c -Wc++-compat (test for warnings, line 17) c-c++-common/Wconversion-pr40752a.c -Wc++-compat (test for warnings, line 19) c-c++-common/Wconversion-pr40752a.c -Wc++-compat (test for warnings, line 40) c-c++-common/Wconversion-pr40752a.c -Wc++-compat (test for warnings, line 42) As a side note, the commit r10-6126-gc77074d05691053ee7347d9e44ab89b3adb23fb1 lacks ChangeLog entries for doc and testsuite, and the commit message does not mention the doc and testsuite changes either.
[Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752 Jason Merrill changed: What|Removed |Added Status|ASSIGNED|RESOLVED Resolution|--- |FIXED Target Milestone|--- |10.0 --- Comment #33 from Jason Merrill --- Fixed for GCC 10.
[Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752 --- Comment #32 from CVS Commits --- The master branch has been updated by Jason Merrill : https://gcc.gnu.org/g:c77074d05691053ee7347d9e44ab89b3adb23fb1 commit r10-6126-gc77074d05691053ee7347d9e44ab89b3adb23fb1 Author: Jason Merrill Date: Tue Jan 7 12:20:26 2020 -0500 PR c++/40752 - useless -Wconversion with short +=. This is a longstanding issue with lots of duplicates; people are not interested in a -Wconversion warning about mychar += 1. So now that warning depends on -Warith-conversion; otherwise we only warn if operands of the arithmetic have conversion issues. * c.opt (-Warith-conversion): New. * c-warn.c (conversion_warning): Recurse for operands of operators. Only warn about the whole expression with -Warith-conversion.
[Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752 Jason Merrill changed: What|Removed |Added CC||kosotiro at yahoo dot gr --- Comment #31 from Jason Merrill --- *** Bug 91312 has been marked as a duplicate of this bug. ***
[Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752 --- Comment #30 from Jason Merrill --- New patch: https://gcc.gnu.org/ml/gcc-patches/2020-01/msg00624.html
[Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752 Jason Merrill changed: What|Removed |Added Status|NEW |ASSIGNED CC||jason at gcc dot gnu.org Assignee|unassigned at gcc dot gnu.org |jason at gcc dot gnu.org
[Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752 Eric Gallager changed: What|Removed |Added CC||msebor at gcc dot gnu.org, ||umesh.kalappa0 at gmail dot com --- Comment #29 from Eric Gallager --- This came up on the gcc mailing list again here: https://gcc.gnu.org/ml/gcc/2018-09/msg00076.html
[Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752 Marcin Ślusarz changed: What|Removed |Added CC||marcin.slusarz at intel dot com --- Comment #28 from Marcin Ślusarz --- *** Bug 67764 has been marked as a duplicate of this bug. ***
[Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752 hariharan.gcc at gmail dot com changed: What|Removed |Added CC||hariharan.gcc at gmail dot com --- Comment #27 from hariharan.gcc at gmail dot com --- I encountered a similar problem with -Wconversion. This option is useless if it would warn for cases like short int i; i += 5; I concede Andrew's point about this being technically a place to warn, but in practice, i would like for it to warn only when the target is a smaller than any of the inputs.
[Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752 Manuel López-Ibáñez manu at gcc dot gnu.org changed: What|Removed |Added CC||dchichkov at gmail dot com --- Comment #26 from Manuel López-Ibáñez manu at gcc dot gnu.org --- *** Bug 61029 has been marked as a duplicate of this bug. ***
[Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752 --- Comment #25 from Chengnian Sun chengniansun at gmail dot com --- Today I encountered a similar case as follows. The conversion warning by gcc is not true as right-shifting an unsigned short decreases the value. BTW clang does not emit warnings for this code snippet. $: cat s1.c unsigned short fn(unsigned short a, int right) { return a right; } $: gcc-trunk -c -Wconversion s1.c s1.c: In function ‘fn’: s1.c:2:3: warning: conversion to ‘short unsigned int’ from ‘int’ may alter its value [-Wconversion] return a right; ^ $: clang-trunk -c -Wconversion s1.c $:
[Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752 Mikhail Veltishchev dichlofos-mv at yandex dot ru changed: What|Removed |Added CC||dichlofos-mv at yandex dot ||ru --- Comment #24 from Mikhail Veltishchev dichlofos-mv at yandex dot ru 2012-06-20 14:57:31 UTC --- Well, please fix this. My cases are instructions like unsigned short x = 100; unsigned short y = 200; // gives a warning x += y;
[Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752 Wes wessjunk at gmail dot com changed: What|Removed |Added CC||wessjunk at gmail dot com --- Comment #22 from Wes wessjunk at gmail dot com 2012-05-05 15:09:22 UTC --- I agree with David. My code has many instances of things like a+=2 where a is a char and this makes -Wconversion useless to me. It's too bad, since it would really be helpful as I am in the process of changing some data types in the code. If someone really thinks there should be a warning for this behavior, how about adding a separate -Wchar-arithmetic warning which warns on all char arithmetic and see how much people use it.
[Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752 --- Comment #23 from Manuel López-Ibáñez manu at gcc dot gnu.org 2012-05-05 15:30:06 UTC --- (In reply to comment #22) If someone really thinks there should be a warning for this behavior, how about adding a separate -Wchar-arithmetic warning which warns on all char arithmetic and see how much people use it. I think adding a new option Wconversion-after-promotion that covers all cases where the conversion occurs to the same type that was originally promoted from would be the most appropriate. I have a feeling that it should not be hard to implement, but I am not sure how, and I have many other things I would like to do first. So, please David, Wes, photon, give it a try. The code is in c-family/c-common.c (conversion_warning).
[Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752 Manuel López-Ibáñez manu at gcc dot gnu.org changed: What|Removed |Added CC||DeusExSophismata at gmail ||dot com --- Comment #20 from Manuel López-Ibáñez manu at gcc dot gnu.org 2012-03-24 19:27:54 UTC --- *** Bug 52703 has been marked as a duplicate of this bug. ***
[Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752 --- Comment #21 from David Stone DeusExSophismata at gmail dot com 2012-03-24 21:25:08 UTC --- Why was this patch rejected, and is there a way to improve it so that obviously safe cases (such as PR52703) are not warned about without having to specify a '-Wno-' option? Yes, according to the standard (C++03 5/9), calculations done on variables smaller than int are first promoted to int, then the calculation is done, then the value is converted back to the target size. However, C++03 1.8/3, the as-if rule, states that it the program can't tell the difference, you can do whatever you want (see my answer to a similar question on Stack Overflow here: http://stackoverflow.com/questions/5563000/implicit-type-conversion-rules-in-c-operators/8935697#8935697). The C++ standard does not require a diagnostic for this, and the apparent behavior is identical. Therefore, there can be no appeals to the C++ standard on the behavior of the warning. Because this is a purely option warning for which gcc defines the rules, we should define it to be useful. If gcc can prove that all of the values are greater than 0 (for instance, if all of the values are unsigned prior to implicit promotion or are positive integral constant expressions), then there is no possibility of having a negative value. Thanks to signed integer overflow being undefined, there is no risk of creating a negative value that way, either. Therefore, we should not warn. Having to manually say Turn off stuff that no one could ever possibly want to see seems like a sure way to make this warning useless.
[Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752 Manuel López-Ibáñez manu at gcc dot gnu.org changed: What|Removed |Added CC||ebrahim at mohammadi dot ir --- Comment #19 from Manuel López-Ibáñez manu at gcc dot gnu.org 2011-09-25 21:12:33 UTC --- *** Bug 50519 has been marked as a duplicate of this bug. ***
[Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
--- Comment #18 from photon at seznam dot cz 2010-06-12 16:46 --- (In reply to comment #17) The patch was rejected but it may be accepted by using a new -Wno-* option to disable these warnings. Perhaps -Wno-conversion-after-promotion? Suggestions are welcome. -Wconversion should be fixed to work as specified. No warning should be generated for the following code: char c = 2; // warning: conversion to char from int may alter its value c = 1; -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752
[Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
--- Comment #17 from manu at gcc dot gnu dot org 2010-06-11 20:22 --- The patch was rejected but it may be accepted by using a new -Wno-* option to disable these warnings. Perhaps -Wno-conversion-after-promotion? Suggestions are welcome. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752
[Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
--- Comment #16 from manu at gcc dot gnu dot org 2009-09-05 14:05 --- *** Bug 41274 has been marked as a duplicate of this bug. *** -- manu at gcc dot gnu dot org changed: What|Removed |Added CC||ashaduri at gmail dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752
[Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
--- Comment #15 from manu at gcc dot gnu dot org 2009-07-23 15:35 --- Patch: http://gcc.gnu.org/ml/gcc-patches/2009-07/msg01179.html -- manu at gcc dot gnu dot org changed: What|Removed |Added URL||http://gcc.gnu.org/ml/gcc- ||patches/2009- ||07/msg01179.html http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752
[Bug c++/40752] -Wconversion generates false warnings for operands not larger than target type
-- photon at seznam dot cz changed: What|Removed |Added Severity|enhancement |normal Summary|-Wconversion: do not warn |-Wconversion generates false |for operands not larger than|warnings for operands not |target type |larger than target type http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40752