diff options
author | mpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4> | 2019-08-15 18:32:33 +0000 |
---|---|---|
committer | mpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4> | 2019-08-15 18:32:33 +0000 |
commit | 900edf070bc6bbd08291abb284f35433ea34ccb1 (patch) | |
tree | c7f2b56da8fdf770d0d91e839aeaac3a549aed6a | |
parent | a1d6728ad7831c1012f6fba7c04135c20e50c356 (diff) |
PR c++/87519 - bogus warning with -Wsign-conversion.
* typeck.c (cp_build_binary_op): Use same_type_p instead of comparing
the types directly.
* g++.dg/warn/Wsign-conversion-5.C: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-9-branch@274545 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/typeck.c | 4 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/warn/Wsign-conversion-5.C | 18 |
3 files changed, 26 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a14a0d6ae0c..42952c68f23 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -7,6 +7,12 @@ * parser.c (cp_parser_constructor_declarator_p): Handle the scenario when a parameter declaration begins with [[attribute]]. + 2019-08-08 Marek Polacek <polacek@redhat.com> + + PR c++/87519 - bogus warning with -Wsign-conversion. + * typeck.c (cp_build_binary_op): Use same_type_p instead of comparing + the types directly. + 2019-08-14 Martin Sebor <msebor@redhat.com> Backported from mainline diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 3255af58a25..bc4a7606582 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -5516,9 +5516,9 @@ cp_build_binary_op (const op_location_t &location, if (! converted) { warning_sentinel w (warn_sign_conversion, short_compare); - if (TREE_TYPE (op0) != result_type) + if (!same_type_p (TREE_TYPE (op0), result_type)) op0 = cp_convert_and_check (result_type, op0, complain); - if (TREE_TYPE (op1) != result_type) + if (!same_type_p (TREE_TYPE (op1), result_type)) op1 = cp_convert_and_check (result_type, op1, complain); if (op0 == error_mark_node || op1 == error_mark_node) diff --git a/gcc/testsuite/g++.dg/warn/Wsign-conversion-5.C b/gcc/testsuite/g++.dg/warn/Wsign-conversion-5.C new file mode 100644 index 00000000000..ff384164901 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wsign-conversion-5.C @@ -0,0 +1,18 @@ +// PR c++/87519 - bogus warning with -Wsign-conversion. +// { dg-options "-Wsign-conversion" } + +typedef unsigned long int uint64_t; + +void f(unsigned long int a, int q) +{ + a += a + q; // { dg-warning "may change the sign" } + + // Explicit cast should disable the warning. + a = a + static_cast<uint64_t>(q); + a = a + (uint64_t) q; + a = a + uint64_t(q); + a = a + static_cast<const uint64_t>(q); + a = a + (const uint64_t) q; + a = a + static_cast<unsigned long int>(q); + a = a + static_cast<const unsigned long int>(q); +} |