This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Go patch committed: Don't permit global variables named init
- From: Ian Lance Taylor <iant at google dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 26 Jun 2013 08:48:06 -0700
- Subject: 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");
+ }
}
}