re PR c++/67065 ([DR 1886] Missing diagnostics for ill-formed program with main varia...
authorPaolo Carlini <paolo@gcc.gnu.org>
Thu, 20 Aug 2015 10:18:03 +0000 (10:18 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Thu, 20 Aug 2015 10:18:03 +0000 (10:18 +0000)
/cp
2015-08-20  Paolo Carlini  <paolo.carlini@oracle.com>

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

/testsuite
2015-08-20  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/67065
* g++.dg/other/pr67065.C: New.

From-SVN: r227027

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/other/pr67065.C [new file with mode: 0644]

index 2a083c804d2944706206aafef5ca3676a9faa9de..53d4febe962804a3a168cfe6dc1ec5a70704c75c 100644 (file)
@@ -1,3 +1,8 @@
+2015-08-20  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/67065
+       * decl.c (grokvardecl): Reject 'main' as global variable.
+
 2015-08-19  Jason Merrill  <jason@redhat.com>
 
        PR c++/66957
index 5c75972136a78b9e788b218ee85d30c53ddb882c..4f77e7c23c42a028813ea1f32a137a36fe4f797a 100644 (file)
@@ -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 be3314444230dffe93d9fc7700761afc9c025b38..36a3d9e271659dfa8d2539ca7e28f2d94248c6b6 100644 (file)
@@ -1,6 +1,12 @@
+2015-08-20  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/67065
+       * g++.dg/other/pr67065.C: New.
+
 2015-08-20  Simon Dardis  <simon.dardis@imgtec.com>
 
-       * gcc.target/mips/inline-memcpy-1.c: Test for inline expansion of memcpy.
+       * gcc.target/mips/inline-memcpy-1.c: Test for inline expansion of
+       memcpy.
        * gcc.target/mips/inline-memcpy-2.c: Ditto.
        * gcc.target/mips/inline-memcpy-3.c: Ditto.
        * gcc.target/mips/inline-memcpy-4.c: Ditto.
diff --git a/gcc/testsuite/g++.dg/other/pr67065.C b/gcc/testsuite/g++.dg/other/pr67065.C
new file mode 100644 (file)
index 0000000..cbf03b2
--- /dev/null
@@ -0,0 +1,3 @@
+// PR c++/67065
+
+int main;  // { dg-error "cannot declare" }