From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28603 invoked by alias); 15 Aug 2018 17:31:02 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 28529 invoked by uid 89); 15 Aug 2018 17:30:58 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-wr1-f67.google.com Received: from mail-wr1-f67.google.com (HELO mail-wr1-f67.google.com) (209.85.221.67) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 15 Aug 2018 17:30:56 +0000 Received: by mail-wr1-f67.google.com with SMTP id h15-v6so1766602wrs.7 for ; Wed, 15 Aug 2018 10:30:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=roHubrY6WTEClBqpMNrwLeCeB3csoDMClONu0WlPC3g=; b=Dq/pGTTAt5Lktrwqf1WNt8W5+nExGrDZn6oXOzWYEwblPlODjSp6NHQHnsjSt4nGcb VZKfmxA05hk9PAyMBrFy76SUHy7enrzg6IrbeJ3WaarLhAphpNHumNm4glmo+CfHs8aY 06Yq6wdGua1o+xDuLXsDQdzisVrw8HCEs/fDY= MIME-Version: 1.0 Received: by 2002:adf:a78a:0:0:0:0:0 with HTTP; Wed, 15 Aug 2018 10:30:47 -0700 (PDT) In-Reply-To: <5cb605d5-8101-552d-4e44-f77067e2668f@redhat.com> References: <5cb605d5-8101-552d-4e44-f77067e2668f@redhat.com> From: Prathamesh Kulkarni Date: Wed, 15 Aug 2018 17:31:00 -0000 Message-ID: Subject: Re: Warning about -Wmain for local variables To: Jeff Law Cc: Jonathan Wakely , gcc Patches , Marek Polacek Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2018-08/txt/msg00898.txt.bz2 On 28 June 2018 at 08:46, Jeff Law wrote: > On 05/30/2018 09:51 AM, Prathamesh Kulkarni wrote: >> On 30 May 2018 at 18:12, Jonathan Wakely wrote: >>> On 30 May 2018 at 11:40, Prathamesh Kulkarni wrote: >>>> gcc with -Wmain warns for local variables named main. >>>> >>>> int foo() >>>> { >>>> int main =3D 0; >>>> return main; >>>> } >>>> >>>> a.c: In function =E2=80=98foo=E2=80=99: >>>> a.c:3:7: warning: =E2=80=98main=E2=80=99 is usually a function [-Wmain] >>>> int main =3D 1; >>>> ^~~~ >>>> >>>> Is this intended ? I assumed that the warning's intent was for >>>> diagnosing variable named main having only external linkage. >>> It was added more than 20 years ago by https://gcc.gnu.org/r13517 and >>> looks like it has always worked as it does now, without considering >>> linkage. >>> >>> Only warning for entities with external linkage seems reasonable to >>> me, but that would be for the C front-end or diagnostics maintainers >>> to decide. >> Thanks for the suggestions. I have attached (untested) patch that warns >> for Wmain if TREE_PUBLIC (decl) is true. >> Does it look OK ? >> >> Thanks, >> Prathamesh >> >> >> wmain-1.txt >> >> >> 2018-05-30 Prathamesh Kulkarni >> >> * c/c-decl.c (start_decl): Add check TREE_PUBLIC (decl) for -Wmain. >> >> testsuite/ >> * gcc.dg/wmain.c: New. > After the usual testing, this is OK. Sorry for late response. I committed the patch after bootstrap+test on x86_= 64. Regards, Prathamesh > > jeff