From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 81589 invoked by alias); 19 Jul 2018 13:01:18 -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 81448 invoked by uid 89); 19 Jul 2018 13:01:09 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-2.8 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=H*i:sk:5B5050B, H*f:sk:5B5050B, programmer, D*mutluit.com X-HELO: resqmta-po-08v.sys.comcast.net Received: from resqmta-po-08v.sys.comcast.net (HELO resqmta-po-08v.sys.comcast.net) (96.114.154.167) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 19 Jul 2018 13:01:08 +0000 Received: from resomta-po-18v.sys.comcast.net ([96.114.154.242]) by resqmta-po-08v.sys.comcast.net with ESMTP id g7oZfGk2UAYWKg8YMfv01f; Thu, 19 Jul 2018 13:01:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20161114; t=1532005266; bh=BedhK/w6Pvg7bLUPFh5UIALeQvo1fltgySUJgVGZ3BE=; h=Received:Received:From:Content-Type:Mime-Version:Subject:Date:To: Message-Id; b=mzhQWpZajs5ft138pCw0GXwLlibtm/thizMAdWyjV7J2vG3M4UTNfCZ6hX8Np62G5 SY5vl5qFiFOjMsz4/6kRtkBxUJxP2TqlhWZDZuPtYG+kHEmaZPrhuPDgJiPrhM6xF4 +YPPoOhmWU8jOsY4s1lBPD2Ter4cP0iut0Xk73XR3J09VY8yBdLLf0H8oUr8tJyFh2 4MxfMs7mHviElRulbLO79sQpRVmpW9ouFwGZ90MGPygXZ+GRHptqu6yvqtIAQ+j7Fr A/+aGYT3Hc2MKv/25xK75C1IAEhWbbDOY8Hh3mIjKQE6KGhb7tbowVwup8OKfMSt6x oE3eKaKWJE8YQ== Received: from [192.168.10.125] ([73.60.223.101]) by resomta-po-18v.sys.comcast.net with ESMTPA id g8YLfsrlcohbhg8YMfz7oZ; Thu, 19 Jul 2018 13:01:06 +0000 From: Paul Koning Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\)) Subject: Re: Detecting superfluous "else" Date: Thu, 19 Jul 2018 13:11:00 -0000 References: <5B5050B2.3010701@mutluit.com> To: GCC Mailing List In-Reply-To: <5B5050B2.3010701@mutluit.com> Message-Id: <38C3E7B4-3B5F-4947-9E8D-2BF60715C6DA@comcast.net> X-SW-Source: 2018-07/txt/msg00277.txt.bz2 > On Jul 19, 2018, at 4:49 AM, U.Mutlu wrote: >=20 > Hi, > it makes me 'crazy' when I see such if-else constructs: > if (x) > return 7; > else > return 4; >=20 > (Of course in this case one better would use the shorthand "return x ? 7 = : 4;", but that's not the issue here) >=20 > The 'else' is obviously superfluous/redundant, ie. unneeded at all: > if (x) > return 7; > return 4; >=20 > 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 -W= redundant-else or so. I don't see any reason to warn about that code. It's perfectly valid, and = in my view is clearer than the alternative. I've written both but I most o= ften write the "else" variant for the reason that it expresses the semantic= s explicitly. Warnings are appropriate for code that is known to be a source of bugs, or = where there is a reasonable chance that the intent of the programmer doesn'= t match what was actually written. That's not the case here. paul