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 importing a package as "init"


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);

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