From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 95116 invoked by alias); 19 Jul 2018 08:50:05 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 95064 invoked by uid 89); 19 Jul 2018 08:50:03 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS,TVD_RCVD_SPACE_BRACKET autolearn=ham version=3.3.2 spammy=Hx-languages-length:500, thx, crazy X-HELO: mutluit.com Received: from mutluit.com (HELO mutluit.com) (82.211.8.197) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 19 Jul 2018 08:50:02 +0000 Received: from [127.0.0.1] (s2.mutluit.com [82.211.8.197]:51020) by mutluit.com ([192.168.20.2]:50025) with ESMTP ([XMail 1.27 ESMTP Server]) id for from ; Thu, 19 Jul 2018 10:49:59 +0200 From: "U.Mutlu" Subject: Detecting superfluous "else" To: gcc@gcc.gnu.org Message-ID: <5B5050B2.3010701@mutluit.com> Date: Thu, 19 Jul 2018 09:12:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:40.0) Gecko/20100101 Firefox/40.0 SeaMonkey/2.37a1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2018-07/txt/msg00273.txt.bz2 Hi, it makes me 'crazy' when I see such if-else constructs: if (x) return 7; else return 4; (Of course in this case one better would use the shorthand "return x ? 7 : 4;", but that's not the issue here) The 'else' is obviously superfluous/redundant, ie. unneeded at all: if (x) return 7; return 4; Is it possible to warn about such unneccessary occurances of "else"? If not, then I suggest to add a new warning code -Wsuperfluous-else or -Wredundant-else or so. Thx