From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 57127 invoked by alias); 7 Jun 2018 19:44:54 -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 57117 invoked by uid 89); 7 Jun 2018 19:44:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.4 required=5.0 tests=AWL,BAYES_00,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=HX-Received:sk:r14-v6m, ac X-HELO: mail-wr0-f194.google.com Received: from mail-wr0-f194.google.com (HELO mail-wr0-f194.google.com) (209.85.128.194) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 07 Jun 2018 19:44:52 +0000 Received: by mail-wr0-f194.google.com with SMTP id w7-v6so11018121wrn.6 for ; Thu, 07 Jun 2018 12:44:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=kzQJKmkBdJudXYk8pZwd2l1RdY/kcqqZDsfiKmSZIHY=; b=L8f8nzGhQ962wAPrNDjKPVCsyxdM18cWfq8CuOx+d63Q48b2+pI4KHyyylwBzO1Mjp vhcG/KnpOUYvwG0ppRXXbQwi7g3LzvMHPzq+bIM5/4NFxijBYlG87GPWyrQqOlfuVXjL LsSboBMFn3aN8EOIByMbIU5iClGrvj9Rr2/zpfe1G7ERTR1p2kPJj3GnqPZHzrIsGXSx ffo8y53bYDWE3MzIun1hzr1AW7rp2qKSWHqeHNcv1U9Z5di14BF/jc8s5YK5Ze6iH2y1 oo17IIGx/Ek3so4hJPlKB/wBJVMAxbEzOYMx1z5P5ea2I8ZSluKLeybmdVEHiTl2ldm3 Ls5w== X-Gm-Message-State: APt69E1H/GO4eo0WtbMJkZXHgSQC4dw+mpZJsEtZ8TOSC3zJZq/gue8A zASi+SltdEP2tWAVGl9Bsij/hM0qkw2o0EnNLPpKlw== X-Google-Smtp-Source: ADUXVKIZY9XEyDF13lBcCofnSB0mR79tspIfZZCKaKSoLFedFHhKRs6zoyuIzvma78XXyJluvVAvRaF1THEO5jaAvpM= X-Received: by 2002:adf:da4e:: with SMTP id r14-v6mr2681506wrl.154.1528400690307; Thu, 07 Jun 2018 12:44:50 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:adf:a782:0:0:0:0:0 with HTTP; Thu, 7 Jun 2018 12:44:49 -0700 (PDT) In-Reply-To: References: From: Prathamesh Kulkarni Date: Thu, 07 Jun 2018 19:44:00 -0000 Message-ID: Subject: Re: Warning about -Wmain for local variables To: Jonathan Wakely Cc: gcc Patches , Marek Polacek Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2018-06/txt/msg00413.txt.bz2 On 30 May 2018 at 21:21, 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 ? ping https://gcc.gnu.org/ml/gcc-patches/2018-05/msg01739.html Thanks, Prathamesh > > Thanks, > Prathamesh