* Re: Warning about -Wmain for local variables
[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
0 siblings, 2 replies; 4+ messages in thread
From: Prathamesh Kulkarni @ 2018-05-30 16:05 UTC (permalink / raw)
To: Jonathan Wakely; +Cc: gcc Patches, Marek Polacek
[-- Attachment #1: Type: text/plain, Size: 1004 bytes --]
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
[-- Attachment #2: wmain-1.txt --]
[-- Type: text/plain, Size: 1142 bytes --]
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.
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index 3c4b18edf56..c5311741629 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -4700,7 +4700,8 @@ start_decl (struct c_declarator *declarator, struct c_declspecs *declspecs,
if (expr)
add_stmt (fold_convert (void_type_node, expr));
- if (TREE_CODE (decl) != FUNCTION_DECL && MAIN_NAME_P (DECL_NAME (decl)))
+ if (TREE_CODE (decl) != FUNCTION_DECL && MAIN_NAME_P (DECL_NAME (decl))
+ && TREE_PUBLIC (decl))
warning (OPT_Wmain, "%q+D is usually a function", decl);
if (initialized)
diff --git a/gcc/testsuite/gcc.dg/wmain.c b/gcc/testsuite/gcc.dg/wmain.c
new file mode 100644
index 00000000000..06fc26fd398
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/wmain.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-Wall" } */
+
+int main; /* { dg-warning "'main' is usually a function" } */
+
+int foo()
+{
+ int main = 1; /* { dg-bogus "'main' is usually a function" } */
+ return main;
+}
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Warning about -Wmain for local variables
2018-05-30 16:05 ` Warning about -Wmain for local variables Prathamesh Kulkarni
@ 2018-06-07 19:44 ` Prathamesh Kulkarni
2018-06-28 3:17 ` Jeff Law
1 sibling, 0 replies; 4+ messages in thread
From: Prathamesh Kulkarni @ 2018-06-07 19:44 UTC (permalink / raw)
To: Jonathan Wakely; +Cc: gcc Patches, Marek Polacek
On 30 May 2018 at 21:21, Prathamesh Kulkarni
<prathamesh.kulkarni@linaro.org> 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 ?
ping https://gcc.gnu.org/ml/gcc-patches/2018-05/msg01739.html
Thanks,
Prathamesh
>
> Thanks,
> Prathamesh
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Warning about -Wmain for local variables
2018-05-30 16:05 ` Warning about -Wmain for local variables Prathamesh Kulkarni
2018-06-07 19:44 ` Prathamesh Kulkarni
@ 2018-06-28 3:17 ` Jeff Law
2018-08-15 17:31 ` Prathamesh Kulkarni
1 sibling, 1 reply; 4+ messages in thread
From: Jeff Law @ 2018-06-28 3:17 UTC (permalink / raw)
To: Prathamesh Kulkarni, Jonathan Wakely; +Cc: gcc Patches, Marek Polacek
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.
jeff
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Warning about -Wmain for local variables
2018-06-28 3:17 ` Jeff Law
@ 2018-08-15 17:31 ` Prathamesh Kulkarni
0 siblings, 0 replies; 4+ messages in thread
From: Prathamesh Kulkarni @ 2018-08-15 17:31 UTC (permalink / raw)
To: Jeff Law; +Cc: Jonathan Wakely, gcc Patches, Marek Polacek
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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-08-15 17:31 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <CAAgBjM=_+e15aot6rZVEF3zZuNi5c9d2UFEQu5aSdF6nD-shgw@mail.gmail.com>
[not found] ` <CAH6eHdS-LNdgsJo4PBaAJS0_U+q4LhAfsQnF=P5-87qkifkk9Q@mail.gmail.com>
2018-05-30 16:05 ` Warning about -Wmain for local variables Prathamesh Kulkarni
2018-06-07 19:44 ` Prathamesh Kulkarni
2018-06-28 3:17 ` Jeff Law
2018-08-15 17:31 ` Prathamesh Kulkarni
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).