This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Go patch committed: Don't permit importing a package as "init"
- From: Ian Lance Taylor <iant at google dot com>
- To: gcc-patches at gcc dot gnu dot org, gofrontend-dev at googlegroups dot com
- Date: Thu, 12 Dec 2013 11:25:31 -0800
- Subject: Go patch committed: Don't permit importing a package as "init"
- Authentication-results: sourceware.org; auth=none
In Go the top-level name "init" is special, as it names a function that
is run when the program starts. The language therefore does not permit
other uses of "init" at top level. This change to the Go frontend
detects and bans one of those cases: importing a package under the local
name "init". Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu. Committed to mainline.
Ian
diff -r 8a7a4f1b970f go/gogo.cc
--- a/go/gogo.cc Thu Dec 12 10:36:16 2013 -0800
+++ b/go/gogo.cc Thu Dec 12 11:23:20 2013 -0800
@@ -440,6 +440,9 @@
return;
}
+ if (local_name == "init")
+ error_at(location, "cannot import package as init");
+
if (filename == "unsafe")
{
this->import_unsafe(local_name, is_local_name_exported, location);