From: Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
To: Jeff Law <law@redhat.com>
Cc: Jonathan Wakely <jwakely.gcc@gmail.com>,
gcc Patches <gcc-patches@gcc.gnu.org>,
Marek Polacek <polacek@redhat.com>
Subject: Re: Warning about -Wmain for local variables
Date: Wed, 15 Aug 2018 17:31:00 -0000 [thread overview]
Message-ID: <CAAgBjMmfa0QQM68t23vpFC4Uq89n0ANSypwq8xH+DcwehMzGyQ@mail.gmail.com> (raw)
In-Reply-To: <5cb605d5-8101-552d-4e44-f77067e2668f@redhat.com>
On 28 June 2018 at 08:46, Jeff Law <law@redhat.com> wrote:
> On 05/30/2018 09:51 AM, Prathamesh Kulkarni wrote:
>> On 30 May 2018 at 18:12, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
>>> On 30 May 2018 at 11:40, Prathamesh Kulkarni wrote:
>>>> gcc with -Wmain warns for local variables named main.
>>>>
>>>> int foo()
>>>> {
>>>> int main = 0;
>>>> return main;
>>>> }
>>>>
>>>> a.c: In function ‘foo’:
>>>> a.c:3:7: warning: ‘main’ is usually a function [-Wmain]
>>>> int main = 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 <prathamesh.kulkarni@linaro.org>
>>
>> * 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
prev parent reply other threads:[~2018-08-15 17:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAAgBjM=_+e15aot6rZVEF3zZuNi5c9d2UFEQu5aSdF6nD-shgw@mail.gmail.com>
[not found] ` <CAH6eHdS-LNdgsJo4PBaAJS0_U+q4LhAfsQnF=P5-87qkifkk9Q@mail.gmail.com>
2018-05-30 16:05 ` Prathamesh Kulkarni
2018-06-07 19:44 ` Prathamesh Kulkarni
2018-06-28 3:17 ` Jeff Law
2018-08-15 17:31 ` Prathamesh Kulkarni [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAAgBjMmfa0QQM68t23vpFC4Uq89n0ANSypwq8xH+DcwehMzGyQ@mail.gmail.com \
--to=prathamesh.kulkarni@linaro.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=jwakely.gcc@gmail.com \
--cc=law@redhat.com \
--cc=polacek@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).