Hi,

submitter noticed that, in violation of [basic.start.main], we don't reject as ill-formed the declaration of a 'main' variable in the global namespace. Not a big deal IMHO, but the below simple check works well for me on x86_64-linux.

Thanks,
Paolo.

//////////////////////////////
/cp
2015-08-19  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/67065
        * decl.c (grokvardecl): Reject 'main' as global variable.

/testsuite
2015-08-19  Paolo Carlini  <paolo.carl...@oracle.com>

        PR c++/67065
        * g++.dg/other/pr67065.C: New.
Index: cp/decl.c
===================================================================
--- cp/decl.c   (revision 227003)
+++ cp/decl.c   (working copy)
@@ -8355,6 +8355,11 @@ grokvardecl (tree type,
   else
     DECL_INTERFACE_KNOWN (decl) = 1;
 
+  if (DECL_NAME (decl)
+      && MAIN_NAME_P (DECL_NAME (decl))
+      && CP_DECL_CONTEXT (decl) == global_namespace)
+    error ("cannot declare %<::main%> to be a global variable");
+
   /* Check that the variable can be safely declared as a concept.
      Note that this also forbids explicit specializations.  */
   if (conceptp)
Index: testsuite/g++.dg/other/pr67065.C
===================================================================
--- testsuite/g++.dg/other/pr67065.C    (revision 0)
+++ testsuite/g++.dg/other/pr67065.C    (working copy)
@@ -0,0 +1,3 @@
+// PR c++/67065
+
+int main;  // { dg-error "cannot declare" }

Reply via email to