From 0cd020ae59e1131b8d7e23424c319c493745f0f8 Mon Sep 17 00:00:00 2001 From: Prathamesh Kulkarni Date: Wed, 15 Aug 2018 15:52:22 +0000 Subject: [PATCH] c-decl.c (start_decl): Do not warn if variables is named as main and is a local variable. 2018-08-15 Prathamesh Kulkarni c/ * c-decl.c (start_decl): Do not warn if variables is named as main and is a local variable. testsuite/ * gcc.dg/wmain.c: New test. From-SVN: r263562 --- gcc/c/ChangeLog | 5 +++++ gcc/c/c-decl.c | 3 ++- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/wmain.c | 10 ++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/wmain.c diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 59312062d96..be714d28b4d 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,8 @@ +2018-08-15 Prathamesh Kulkarni + + * c-decl.c (start_decl): Do not warn if variables is named as main + and is a local variable. + 2018-08-15 Iain Sandoe PR c/19315 diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index da42add0732..1bbccddab31 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/ChangeLog b/gcc/testsuite/ChangeLog index 18bb966ca42..0bcf92fe7d2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2018-08-15 Prathamesh Kulkarni + + * gcc.dg/wmain.c: New test. + 2018-08-15 Iain Sandoe PR c/19315 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; +} -- 2.30.2