c-decl.c (start_decl): Do not warn if variables is named as main and is a local variable.
authorPrathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
Wed, 15 Aug 2018 15:52:22 +0000 (15:52 +0000)
committerPrathamesh Kulkarni <prathamesh3492@gcc.gnu.org>
Wed, 15 Aug 2018 15:52:22 +0000 (15:52 +0000)
2018-08-15  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>

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
gcc/c/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/wmain.c [new file with mode: 0644]

index 5931206..be714d2 100644 (file)
@@ -1,3 +1,8 @@
+2018-08-15  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>
+       
+       * c-decl.c (start_decl): Do not warn if variables is named as main
+       and is a local variable.
+
 2018-08-15  Iain Sandoe  <iain@sandoe.co.uk>
 
        PR c/19315
index da42add..1bbccdd 100644 (file)
@@ -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)
index 18bb966..0bcf92f 100644 (file)
@@ -1,3 +1,7 @@
+2018-08-15  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>
+
+       * gcc.dg/wmain.c: New test.
+
 2018-08-15  Iain Sandoe  <iain@sandoe.co.uk>
 
        PR c/19315
diff --git a/gcc/testsuite/gcc.dg/wmain.c b/gcc/testsuite/gcc.dg/wmain.c
new file mode 100644 (file)
index 0000000..06fc26f
--- /dev/null
@@ -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;
+}