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 59312062d96ca5518e376393b34573a56cfd48e1..be714d28b4d4efd5d2a33d0c631e14e3698586c3 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 da42add07327d733d6fd7e48d21843ff81d04041..1bbccddab31de598516ecacb3f43370951a408d0 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 18bb966ca42dfda9bcf8c344428402d23c26ec3b..0bcf92fe7d2eff0dc7b6bc5987b101e7f2324a0b 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;
+}