From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id C38C73861830; Mon, 21 Jun 2021 20:42:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C38C73861830 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-8628] c++: remove redundant warning [PR100879] X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 4c4bebb834ec19d68ef7248510cfe2548d864454 X-Git-Newrev: 4f2819223873266b4cdfa7af54752a37d1ebd665 Message-Id: <20210621204242.C38C73861830@sourceware.org> Date: Mon, 21 Jun 2021 20:42:42 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Jun 2021 20:42:42 -0000 https://gcc.gnu.org/g:4f2819223873266b4cdfa7af54752a37d1ebd665 commit r11-8628-g4f2819223873266b4cdfa7af54752a37d1ebd665 Author: Jason Merrill Date: Tue Jun 8 17:48:49 2021 -0400 c++: remove redundant warning [PR100879] Before my r277864, build_new_op promoted enums to int before passing them on to cp_build_binary_op; after that commit, it doesn't, so warn_for_sign_compare sees the enum operands and gives a redundant warning. This warning dates back to 1995, and seems to have been dead code for a long time--likely since build_new_op was added in 1997--so let's just remove it. PR c++/100879 gcc/c-family/ChangeLog: * c-warn.c (warn_for_sign_compare): Remove C++ enum mismatch warning. gcc/testsuite/ChangeLog: * g++.dg/diagnostic/enum3.C: New test. Diff: --- gcc/c-family/c-warn.c | 12 ------------ gcc/testsuite/g++.dg/diagnostic/enum3.C | 9 +++++++++ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/gcc/c-family/c-warn.c b/gcc/c-family/c-warn.c index c48dc2e6d24..7414063aa11 100644 --- a/gcc/c-family/c-warn.c +++ b/gcc/c-family/c-warn.c @@ -2240,18 +2240,6 @@ warn_for_sign_compare (location_t location, int op1_signed = !TYPE_UNSIGNED (TREE_TYPE (orig_op1)); int unsignedp0, unsignedp1; - /* In C++, check for comparison of different enum types. */ - if (c_dialect_cxx() - && TREE_CODE (TREE_TYPE (orig_op0)) == ENUMERAL_TYPE - && TREE_CODE (TREE_TYPE (orig_op1)) == ENUMERAL_TYPE - && TYPE_MAIN_VARIANT (TREE_TYPE (orig_op0)) - != TYPE_MAIN_VARIANT (TREE_TYPE (orig_op1))) - { - warning_at (location, - OPT_Wsign_compare, "comparison between types %qT and %qT", - TREE_TYPE (orig_op0), TREE_TYPE (orig_op1)); - } - /* Do not warn if the comparison is being done in a signed type, since the signed type will only be chosen if it can represent all the values of the unsigned type. */ diff --git a/gcc/testsuite/g++.dg/diagnostic/enum3.C b/gcc/testsuite/g++.dg/diagnostic/enum3.C new file mode 100644 index 00000000000..d51aa8a0f70 --- /dev/null +++ b/gcc/testsuite/g++.dg/diagnostic/enum3.C @@ -0,0 +1,9 @@ +// PR c++/100879 +// { dg-additional-options -Werror=sign-compare } + +enum e1 { e1val }; +enum e2 { e3val }; + +int main( int, char * [] ) { + if ( e1val == e3val ) return 1; // { dg-warning -Wenum-compare } +}