This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Go patch committed: Don't permit global variables named init


The Go language does not permit global variables named init.  That name
is reserved for functions that run when the program starts.  This patch,
from RÃmy Oudompheng, implements that restriction in gccgo.
Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline and 4.8 branch.

Ian

diff -r f250c0138323 go/gogo.cc
--- a/go/gogo.cc	Tue Jun 25 09:27:11 2013 -0700
+++ b/go/gogo.cc	Wed Jun 26 08:46:11 2013 -0700
@@ -1278,6 +1278,14 @@
 		   n.c_str());
 	  inform(pf->second, "%qs imported here", n.c_str());
 	}
+
+      // No package scope identifier may be named "init".
+      if (!p->second->is_function()
+	  && Gogo::unpack_hidden_name(p->second->name()) == "init")
+	{
+	  error_at(p->second->location(),
+	           "cannot declare init - must be func");
+	}
     }
 }
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]