From 60bb944817d35ec0f01e5b78a5f248dabad8b7ca Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Thu, 8 Aug 2019 15:37:46 +0000 Subject: [PATCH] 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. From-SVN: r274211 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/typeck.c | 4 ++-- gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/g++.dg/warn/Wsign-conversion-5.C | 18 ++++++++++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/warn/Wsign-conversion-5.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 3af901c78ea..4d78888f38b 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2019-08-08 Marek Polacek + PR c++/87519 - bogus warning with -Wsign-conversion. + * typeck.c (cp_build_binary_op): Use same_type_p instead of comparing + the types directly. + * constexpr.c (inline_asm_in_constexpr_error): New. (cxx_eval_constant_expression) : Call it. (potential_constant_expression_1) : Likewise. diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 7e4ea3bee75..4cc0ee0128d 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -5509,9 +5509,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/ChangeLog b/gcc/testsuite/ChangeLog index be085243d37..6ed8aabaec8 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2019-08-08 Marek Polacek + PR c++/87519 - bogus warning with -Wsign-conversion. + * g++.dg/warn/Wsign-conversion-5.C: New test. + * g++.dg/cpp2a/inline-asm3.C: New test. 2019-08-07 Steven G. Kargl 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(q); + a = a + (uint64_t) q; + a = a + uint64_t(q); + a = a + static_cast(q); + a = a + (const uint64_t) q; + a = a + static_cast(q); + a = a + static_cast(q); +} -- 2.30.2